-
Notifications
You must be signed in to change notification settings - Fork 12
/
app.js
30 lines (30 loc) · 1.22 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var Bugsnag = require('@bugsnag/js')
var BugsnagPluginExpress = require('@bugsnag/plugin-express')
Bugsnag.start({
apiKey: process.env.BUGSNAG_API_KEY || "5b0414a9a476d93d154fa294c76ac6ed",
plugins: [BugsnagPluginExpress],
})
var express = require('express')
var app = express()
var middleware = Bugsnag.getPlugin('express')
// This must be the first piece of middleware in the stack.
// It can only capture errors in downstream middleware
app.use(middleware.requestHandler)
app.use(express.static('src'))
// CORS (Cross-Origin Resource Sharing) headers to support Cross-site HTTP requests
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*")
res.header("Access-Control-Allow-Headers", "X-Requested-With")
next()
})
//The 404 Route (ALWAYS Keep this as the last route)
app.get('*', function(req, res){
res.status(404).send('what???')
})
app.set('port', process.env.PORT || 5000)
app.listen(app.get('port'), function () {
console.log('Express server listening on port ' + app.get('port'))
})
// This handles any errors that Express catches. This needs to go before other
// error handlers. Bugsnag will call the `next` error handler if it exists.
app.use(middleware.errorHandler)