mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 17:12:43 +00:00
feat: move up and enable cors
This commit is contained in:
committed by
Rainer Killinger
parent
c61c37dc27
commit
6483221b62
48
src/app.ts
48
src/app.ts
@@ -47,6 +47,30 @@ export async function configureApp(app: Express) {
|
|||||||
// request loggers have to be the first middleware to be set in express
|
// request loggers have to be the first middleware to be set in express
|
||||||
app.use(morgan('dev'));
|
app.use(morgan('dev'));
|
||||||
|
|
||||||
|
const corsOptions = {
|
||||||
|
allowedHeaders: [
|
||||||
|
'DNT',
|
||||||
|
'Keep-Alive',
|
||||||
|
'User-Agent',
|
||||||
|
'X-Requested-With',
|
||||||
|
'If-Modified-Since',
|
||||||
|
'Cache-Control',
|
||||||
|
'Content-Type',
|
||||||
|
'X-StApps-Version',
|
||||||
|
],
|
||||||
|
credentials: true,
|
||||||
|
maxAge: 1728000,
|
||||||
|
methods: ['GET', 'POST', 'PUT', 'OPTIONS'],
|
||||||
|
optionsSuccessStatus: 204,
|
||||||
|
};
|
||||||
|
|
||||||
|
// allow all origins on all routes
|
||||||
|
app.use(cors(corsOptions));
|
||||||
|
// TODO: See if it can handle options request with no content-type
|
||||||
|
|
||||||
|
// allow cors preflight requests on every route
|
||||||
|
app.options('*', cors(corsOptions));
|
||||||
|
|
||||||
// only accept json as content type for all requests
|
// only accept json as content type for all requests
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
// get the content type
|
// get the content type
|
||||||
@@ -158,30 +182,6 @@ export async function configureApp(app: Express) {
|
|||||||
|
|
||||||
app.set('env', process.env.NODE_ENV);
|
app.set('env', process.env.NODE_ENV);
|
||||||
|
|
||||||
const corsOptions = {
|
|
||||||
allowedHeaders: [
|
|
||||||
'DNT',
|
|
||||||
'Keep-Alive',
|
|
||||||
'User-Agent',
|
|
||||||
'X-Requested-With',
|
|
||||||
'If-Modified-Since',
|
|
||||||
'Cache-Control',
|
|
||||||
'Content-Type',
|
|
||||||
'X-StApps-Version',
|
|
||||||
],
|
|
||||||
credentials: true,
|
|
||||||
maxAge: 1728000,
|
|
||||||
methods: ['GET', 'POST', 'PUT', 'OPTIONS'],
|
|
||||||
optionsSuccessStatus: 204,
|
|
||||||
};
|
|
||||||
|
|
||||||
// allow all origins on all routes
|
|
||||||
app.use(cors(corsOptions));
|
|
||||||
// TODO: See if it can handle options request with no content-type
|
|
||||||
|
|
||||||
// allow cors preflight requests on every route
|
|
||||||
app.options('*', cors(corsOptions));
|
|
||||||
|
|
||||||
// load routes before plugins
|
// load routes before plugins
|
||||||
// they now can be used or overwritten by any plugin
|
// they now can be used or overwritten by any plugin
|
||||||
app.use(
|
app.use(
|
||||||
|
|||||||
Reference in New Issue
Block a user