chore: Adjust cors options
This commit is contained in:
@@ -1,2 +1,5 @@
|
||||
HOST=localhost
|
||||
PROTOCOL=http
|
||||
PORT=3000
|
||||
CORS_PORT=3001
|
||||
APP_ENV=development
|
||||
|
@@ -9,6 +9,7 @@
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
"debug": "~2.6.9",
|
||||
"dotenv": "^10.0.0",
|
||||
"express": "~4.16.1",
|
||||
@@ -40,6 +41,7 @@
|
||||
"url": "https://github.com/automatisch/automatisch/issues"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/cors": "^2.8.12",
|
||||
"@types/express": "^4.17.13",
|
||||
"@types/http-errors": "^1.8.1",
|
||||
"@types/morgan": "^1.9.3",
|
||||
|
@@ -1,6 +1,8 @@
|
||||
import appConfig from './config/app'
|
||||
import createError from 'http-errors';
|
||||
import express, { Request, Response, NextFunction } from 'express';
|
||||
import cors from 'cors';
|
||||
import corsOptions from './config/cors-options';
|
||||
import { graphqlHTTP } from 'express-graphql';
|
||||
import logger from './helpers/logger';
|
||||
import morgan from './helpers/morgan';
|
||||
@@ -15,6 +17,8 @@ app.use(morgan);
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: false }));
|
||||
|
||||
app.use(cors(corsOptions))
|
||||
|
||||
app.use(
|
||||
'/graphql',
|
||||
graphqlHTTP({
|
||||
|
@@ -2,12 +2,18 @@ import * as dotenv from 'dotenv';
|
||||
dotenv.config();
|
||||
|
||||
type AppConfig = {
|
||||
host: string,
|
||||
protocol: string
|
||||
port: string,
|
||||
corsPort: string,
|
||||
appEnv: string,
|
||||
}
|
||||
|
||||
const appConfig: AppConfig = {
|
||||
host: process.env.HOST || 'localhost',
|
||||
protocol: process.env.PROTOCOL || 'http',
|
||||
port: process.env.PORT || '3000',
|
||||
corsPort: process.env.CORS_PORT || '3001',
|
||||
appEnv: process.env.APP_ENV || 'development',
|
||||
}
|
||||
|
||||
|
10
packages/backend/src/config/cors-options.ts
Normal file
10
packages/backend/src/config/cors-options.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import appConfig from './app'
|
||||
|
||||
const corsOptions = {
|
||||
origin: `${appConfig.protocol}://${appConfig.host}:${appConfig.corsPort}`,
|
||||
methods: 'POST',
|
||||
credentials: true,
|
||||
optionsSuccessStatus: 200,
|
||||
}
|
||||
|
||||
export default corsOptions;
|
Reference in New Issue
Block a user