add empty frontend application, prepare everything
This commit is contained in:
@@ -1,30 +1,22 @@
|
||||
import express, { NextFunction, Request, Response } from 'express';
|
||||
import ejsMate from 'ejs-mate';
|
||||
import router from './router';
|
||||
|
||||
const { PORT = 3000 } = process.env;
|
||||
|
||||
const app = express();
|
||||
|
||||
app.engine('ejs', ejsMate);
|
||||
app.set('views', '/opt/app/views');
|
||||
app.set('view engine', 'ejs');
|
||||
app.use('/api', router.router);
|
||||
|
||||
app.use(router.router);
|
||||
|
||||
app.use('/dist/bootstrap', express.static('/opt/app/public'));
|
||||
|
||||
app.use(express.static('/opt/app/public'));
|
||||
|
||||
app.use((req: Request, res: Response, next: NextFunction) => {
|
||||
// 404
|
||||
return next(new Error('404'));
|
||||
});
|
||||
const frontendRoot = '/opt/frontend/dist';
|
||||
app.use(express.static(frontendRoot));
|
||||
app.use((req, res) => res.sendFile(`${frontendRoot}/index.html`));
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
app.use((err, req: Request, res: Response, next: NextFunction) => {
|
||||
// 404
|
||||
res.render('error');
|
||||
console.log('err', err);
|
||||
|
||||
// 500
|
||||
res.status(500).json({ msg: 'an error occurred' });
|
||||
});
|
||||
|
||||
app.listen(PORT, () => {
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import { Router } from 'express';
|
||||
import { Request, Response, Router } from 'express';
|
||||
import fooController from './controllers/foo.controller';
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get('/foo', fooController.getFoo);
|
||||
// aaaaa
|
||||
|
||||
export default { router };
|
||||
router.use((req: Request, res: Response) => {
|
||||
// 404
|
||||
res.status(404).json({ msg: 'the requested resource could not be found' });
|
||||
});
|
||||
|
||||
export default { router };
|
||||
|
||||
@@ -4,4 +4,4 @@ function getFooDetails() {
|
||||
|
||||
export default {
|
||||
getFooDetails,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user