feat: Serve react app through express server
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
d139eb8c06
commit
654e868a23
@@ -1,4 +1,4 @@
|
||||
import appConfig from './config/app'
|
||||
import appConfig from './config/app';
|
||||
import createError from 'http-errors';
|
||||
import express, { Request, Response, NextFunction } from 'express';
|
||||
import cors from 'cors';
|
||||
@@ -7,6 +7,7 @@ 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';
|
||||
@@ -14,7 +15,7 @@ import authentication from './helpers/authentication';
|
||||
const app = express();
|
||||
const port = appConfig.port;
|
||||
|
||||
appAssetsHandler(app)
|
||||
appAssetsHandler(app);
|
||||
|
||||
app.use(morgan);
|
||||
app.use(express.json());
|
||||
@@ -23,13 +24,15 @@ 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) {
|
||||
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}`)
|
||||
})
|
||||
logger.info(`Server is listening on ${port}`);
|
||||
});
|
||||
|
Reference in New Issue
Block a user