Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add routes integration for Express.js
- Loading branch information
1 parent
c4197ec
commit d8e1844
Showing
3 changed files
with
36 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,30 @@ | ||
var express = require('express'); | ||
var AirbrakeClient = require('airbrake-js'); | ||
var makeErrorHandler = require('airbrake-js/dist/instrumentation/express'); | ||
var express = require('express') | ||
var AirbrakeClient = require('airbrake-js') | ||
var airbrakeExpress = require('airbrake-js/dist/instrumentation/express') | ||
|
||
var app = express(); | ||
|
||
app.get('/', function hello (req, res) { | ||
throw new Error('hello from Express'); | ||
res.send('Hello World!'); | ||
}) | ||
var app = express() | ||
|
||
var airbrake = new AirbrakeClient({ | ||
projectId: 1, | ||
projectKey: 'FIXME', | ||
}); | ||
projectKey: 'FIXME' | ||
}) | ||
|
||
// This middleware should be used before any routes are defined. | ||
app.use(airbrakeExpress.makeMiddleware(airbrake)) | ||
|
||
app.get('/', function hello(req, res) { | ||
throw new Error('hello from Express') | ||
res.send('Hello World!') | ||
}) | ||
|
||
app.get('/hello/:name', function hello(req, res) { | ||
res.send(`Hello ${req.params.name}`) | ||
}) | ||
|
||
// Error handler middleware should be the last one. | ||
// See http://expressjs.com/en/guide/error-handling.html | ||
app.use(makeErrorHandler(airbrake)); | ||
app.use(airbrakeExpress.makeErrorHandler(airbrake)) | ||
|
||
app.listen(3000, function () { | ||
console.log('Example app listening on port 3000!'); | ||
app.listen(3000, function() { | ||
console.log('Example app listening on port 3000!') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters