1
0
Fork 0
mirror of https://github.com/codex-team/codex.docs.git synced 2025-07-25 08:09:41 +02:00

Feat/hawk integration (#210)

* update environment variable

* add: hawk nodejs and javascript catcher

* fontend hawk integration

* backend hawk integration

* update the env file and config files

* support for client, backend error tracking token

* client side error tracking refactor

* new version of hawk.nodejs catcher added
This commit is contained in:
Umang G. Patel 2022-07-26 09:56:20 +05:30 committed by GitHub
parent 1fb7bc8dcc
commit 13cc53e4ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 134 additions and 12 deletions

View file

@ -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,18 +7,30 @@ import routes from './routes';
import HttpException from './exceptions/httpException';
import * as dotenv from 'dotenv';
import config from 'config';
import HawkCatcher from '@hawk.so/nodejs';
import os from 'os';
import appConfig from 'config';
import { downloadFavicon, FaviconData } from './utils/downloadFavicon';
dotenv.config();
const app = express();
const localConfig = rcParser.getConfiguration();
// Initialize the backend error tracking catcher.
if (process.env.HAWK_TOKEN_BACKEND) {
HawkCatcher.init(process.env.HAWK_TOKEN_BACKEND);
}
// Get url to upload favicon from config
const favicon: string = appConfig.get('favicon');
app.locals.config = localConfig;
// Set client error tracking token as app local.
if (process.env.HAWK_TOKEN_CLIENT) {
app.locals.config.hawkClientToken = process.env.HAWK_TOKEN_CLIENT;
}
// view engine setup
app.set('views', path.join(__dirname, './', 'views'));
app.set('view engine', 'twig');
@ -55,15 +67,24 @@ app.use('/favicon', express.static(downloadedFaviconFolder));
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');
// global error handler
app.use(function (err: unknown, req: Request, res: Response, next: NextFunction) {
// send any type of error to hawk server.
if (process.env.HAWK_TOKEN_BACKEND && err instanceof Error) {
HawkCatcher.send(err);
}
// only send Http based exception to client.
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;

View file

@ -11,7 +11,8 @@
</head>
<script>
window.config = {
misprintsChatId: "{{ config.misprintsChatId }}"
misprintsChatId: "{{ config.misprintsChatId }}",
hawkClientToken:"{{ config.hawkClientToken }}",
};
</script>
<body>