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;
|
17
yarn.lock
17
yarn.lock
@@ -2949,6 +2949,11 @@
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/cors@^2.8.12":
|
||||
version "2.8.12"
|
||||
resolved "https://registry.yarnpkg.com/@types/cors/-/cors-2.8.12.tgz#6b2c510a7ad7039e98e7b8d3d6598f4359e5c080"
|
||||
integrity sha512-vt+kDhq/M2ayberEtJcIN/hxXy1Pk+59g2FV/ZQceeaTyCtCucjL2Q7FXlFjtWn4n15KCr1NE2lNNFhp0lEThw==
|
||||
|
||||
"@types/eslint@^7.2.6":
|
||||
version "7.28.0"
|
||||
resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-7.28.0.tgz#7e41f2481d301c68e14f483fe10b017753ce8d5a"
|
||||
@@ -5369,6 +5374,14 @@ core-util-is@~1.0.0:
|
||||
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85"
|
||||
integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==
|
||||
|
||||
cors@^2.8.5:
|
||||
version "2.8.5"
|
||||
resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29"
|
||||
integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==
|
||||
dependencies:
|
||||
object-assign "^4"
|
||||
vary "^1"
|
||||
|
||||
cosmiconfig@^5.0.0:
|
||||
version "5.2.1"
|
||||
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-5.2.1.tgz#040f726809c591e77a17c0a3626ca45b4f168b1a"
|
||||
@@ -10614,7 +10627,7 @@ oauth-sign@~0.9.0:
|
||||
resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.9.0.tgz#47a7b016baa68b5fa0ecf3dee08a85c679ac6455"
|
||||
integrity sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==
|
||||
|
||||
object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1:
|
||||
object-assign@^4, object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1:
|
||||
version "4.1.1"
|
||||
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
|
||||
integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=
|
||||
@@ -14830,7 +14843,7 @@ value-equal@^1.0.1:
|
||||
resolved "https://registry.yarnpkg.com/value-equal/-/value-equal-1.0.1.tgz#1e0b794c734c5c0cade179c437d356d931a34d6c"
|
||||
integrity sha512-NOJ6JZCAWr0zlxZt+xqCHNTEKOsrks2HQd4MqhP1qy4z1SkbEP467eNx6TgDKXMvUOb+OENfJCZwM+16n7fRfw==
|
||||
|
||||
vary@~1.1.2:
|
||||
vary@^1, vary@~1.1.2:
|
||||
version "1.1.2"
|
||||
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
|
||||
integrity sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=
|
||||
|
Reference in New Issue
Block a user