Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
feat(server): add Raven, disable x-powered-by
Browse files Browse the repository at this point in the history
  • Loading branch information
Metnew committed Oct 29, 2017
1 parent ff0d42d commit 4c3ed6f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/server/middlewares/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ import cookieParser from 'cookie-parser'
import bodyParser from 'body-parser'
import morgan from 'morgan'
import useragent from 'express-useragent'
import Raven from 'raven'
import authMiddleware from './auth'

export default (app: express$Application): express$Application => {
// Must configure Raven before doing anything else with it
Raven.config(process.env.SENTRY_DSN).install()
// The request handler must be the first middleware on the app
app.use(Raven.requestHandler())
// remove x-powered-by
app.disable('x-powered-by')
// Add express stuff
app.use(helmet())
app.use(compression())
Expand All @@ -25,6 +32,23 @@ export default (app: express$Application): express$Application => {
app.use(bodyParser.json())
app.use(useragent.express())
app.use(authMiddleware)
// The error handler must be before any other error middleware
app.use(Raven.errorHandler())
// Optional fallthrough error handler
// eslint-disable-next-line
app.use(function onError(
err,
req: express$Request,
res: express$Response,
next: express$NextFunction
) {
// NOTE: @Metnew: line disabled by ESlint, because err is already handled by sentry
//
// The error id is attached to `res.sentry` to be returned
// and optionally displayed to the user for support.
res.statusCode = 500
res.end(res.sentry + '\n')
})

return app
}

0 comments on commit 4c3ed6f

Please sign in to comment.