Skip to content

Commit

Permalink
🐛 re-order api middlewares: cors middleware before connect-slashes (#…
Browse files Browse the repository at this point in the history
…7861)

closes #7839

- when a browser sends a request to the API without a trailing slash, we are using connect-slashes to redirect permanently
- but because the CORS middleware was registered after the redirect, the CORS headers got lost
  • Loading branch information
kirrg001 authored and kevinansfield committed Jan 18, 2017
1 parent 2f3081f commit 4a4b2f6
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions core/server/api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,13 @@ var debug = require('debug')('ghost:api'),
authenticatePublic = [
auth.authenticate.authenticateClient,
auth.authenticate.authenticateUser,
auth.authorize.requiresAuthorizedUserPublicAPI,
// @TODO do we really need this multiple times or should it be global?
cors
auth.authorize.requiresAuthorizedUserPublicAPI
],
// Require user for private endpoints
authenticatePrivate = [
auth.authenticate.authenticateClient,
auth.authenticate.authenticateUser,
auth.authorize.requiresAuthorizedUser,
// @TODO do we really need this multiple times or should it be global?
cors
auth.authorize.requiresAuthorizedUser
];

// @TODO refactor/clean this up - how do we want the routing to work long term?
Expand Down Expand Up @@ -226,6 +222,8 @@ module.exports = function setupApiApp() {
apiApp.use(bodyParser.json({limit: '1mb'}));
apiApp.use(bodyParser.urlencoded({extended: true, limit: '1mb'}));

apiApp.use(cors);

// send 503 json response in case of maintenance
apiApp.use(maintenance);

Expand Down

0 comments on commit 4a4b2f6

Please sign in to comment.