Files
automatisch/packages/backend/src/app.ts
2022-02-24 22:48:04 +03:00

39 lines
1.1 KiB
TypeScript

import appConfig from './config/app';
import createError from 'http-errors';
import express, { Request, Response, NextFunction } from 'express';
import cors from 'cors';
import corsOptions from './config/cors-options';
import graphQLInstance from './helpers/graphql-instance';
import logger from './helpers/logger';
import morgan from './helpers/morgan';
import appAssetsHandler from './helpers/app-assets-handler';
import webUIHandler from './helpers/web-ui-handler';
import errorHandler from './helpers/error-handler';
import './config/database';
import authentication from './helpers/authentication';
const app = express();
const port = appConfig.port;
appAssetsHandler(app);
app.use(morgan);
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cors(corsOptions));
app.use(authentication);
app.use('/graphql', graphQLInstance);
webUIHandler(app);
// catch 404 and forward to error handler
app.use(function (req: Request, res: Response, next: NextFunction) {
next(createError(404));
});
app.use(errorHandler);
app.listen(port, () => {
logger.info(`Server is listening on ${port}`);
});