mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-08-05 12:02:13 +00:00
strange fix to CORS issue - move CORS middleware to top, respond with
200 if OPTIONS request
This commit is contained in:
parent
1ddd06ce38
commit
399e4b9dda
2 changed files with 8 additions and 4 deletions
|
|
@ -57,6 +57,7 @@ auth.store(store, habitrpgStore.customAccessControl)
|
||||||
|
|
||||||
mongo_store = new MongoStore {url: process.env.NODE_DB_URI}, ->
|
mongo_store = new MongoStore {url: process.env.NODE_DB_URI}, ->
|
||||||
expressApp
|
expressApp
|
||||||
|
.use(middleware.allowCrossDomain)
|
||||||
.use(express.favicon("#{publicPath}/favicon.ico"))
|
.use(express.favicon("#{publicPath}/favicon.ico"))
|
||||||
# Gzip static files and serve from memory
|
# Gzip static files and serve from memory
|
||||||
.use(gzippo.staticGzip(publicPath, maxAge: ONE_YEAR))
|
.use(gzippo.staticGzip(publicPath, maxAge: ONE_YEAR))
|
||||||
|
|
@ -74,7 +75,6 @@ mongo_store = new MongoStore {url: process.env.NODE_DB_URI}, ->
|
||||||
)
|
)
|
||||||
# Adds req.getModel method
|
# Adds req.getModel method
|
||||||
.use(store.modelMiddleware())
|
.use(store.modelMiddleware())
|
||||||
.use(middleware.allowCrossDomain)
|
|
||||||
# API should be hit before all other routes
|
# API should be hit before all other routes
|
||||||
.use('/api/v1', require('./api').middleware)
|
.use('/api/v1', require('./api').middleware)
|
||||||
.use(require('./deprecated').middleware)
|
.use(require('./deprecated').middleware)
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,10 @@ module.exports.view = (req, res, next) ->
|
||||||
module.exports.allowCrossDomain = (req, res, next) ->
|
module.exports.allowCrossDomain = (req, res, next) ->
|
||||||
console.log req.headers.origin
|
console.log req.headers.origin
|
||||||
res.header "Access-Control-Allow-Origin", (req.headers.origin || "*")
|
res.header "Access-Control-Allow-Origin", (req.headers.origin || "*")
|
||||||
res.header "Access-Control-Allow-Methods", "OPTIONS,GET,PUT,POST,DELETE"
|
res.header "Access-Control-Allow-Methods", "OPTIONS,GET,POST,PUT,HEAD,DELETE"
|
||||||
res.header "Access-Control-Allow-Headers", "Content-Type,x-requested-with,x-api-user,x-api-key"
|
res.header "Access-Control-Allow-Headers", "Content-Type,X-Requested-With,x-api-user,x-api-key"
|
||||||
next()
|
|
||||||
|
if req.method is 'OPTIONS'
|
||||||
|
res.send(200);
|
||||||
|
else
|
||||||
|
next()
|
||||||
Loading…
Reference in a new issue