mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-06 14:05:22 +02:00
backend hawk integration
This commit is contained in:
parent
bec5d52e2b
commit
53a5d94d12
1 changed files with 21 additions and 9 deletions
|
@ -1,4 +1,4 @@
|
|||
import express, { Request, Response } from 'express';
|
||||
import express, { NextFunction, Request, Response } from 'express';
|
||||
import path from 'path';
|
||||
import cookieParser from 'cookie-parser';
|
||||
import morgan from 'morgan';
|
||||
|
@ -7,11 +7,15 @@ import routes from './routes';
|
|||
import HttpException from './exceptions/httpException';
|
||||
import * as dotenv from 'dotenv';
|
||||
import config from 'config';
|
||||
import HawkCatcher from '@hawk.so/nodejs';
|
||||
|
||||
|
||||
dotenv.config();
|
||||
const app = express();
|
||||
const localConfig = rcParser.getConfiguration();
|
||||
|
||||
HawkCatcher.init(process.env.EXPRESS_NODEJS_HAWK_TOKEN || '');
|
||||
|
||||
app.locals.config = localConfig;
|
||||
// view engine setup
|
||||
app.set('views', path.join(__dirname, './', 'views'));
|
||||
|
@ -27,15 +31,23 @@ app.use('/uploads', express.static(config.get('uploads')));
|
|||
|
||||
app.use('/', routes);
|
||||
|
||||
// error handler
|
||||
app.use(function (err: HttpException, req: Request, res: Response) {
|
||||
// set locals, only providing error in development
|
||||
res.locals.message = err.message;
|
||||
res.locals.error = req.app.get('env') === 'development' ? err : {};
|
||||
|
||||
// render the error page
|
||||
res.status(err.status || 500);
|
||||
res.render('error');
|
||||
// error handler
|
||||
app.use(function (err: unknown, req: Request, res: Response, next: NextFunction) {
|
||||
// send error to hawk server.
|
||||
if (err instanceof Error) {
|
||||
HawkCatcher.send(err);
|
||||
}
|
||||
if (err instanceof HttpException) {
|
||||
// set locals, only providing error in development
|
||||
res.locals.message = err.message;
|
||||
res.locals.error = req.app.get('env') === 'development' ? err : {};
|
||||
// render the error page
|
||||
res.status(err.status || 500);
|
||||
res.render('error');
|
||||
}
|
||||
next(err);
|
||||
});
|
||||
|
||||
|
||||
export default app;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue