more moving, add router and example service and controller

This commit is contained in:
2022-09-30 09:21:46 +02:00
parent b5eafd0a96
commit 57db5860e3
6 changed files with 40 additions and 12 deletions

View File

@@ -1,17 +1,20 @@
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', '/app/views');
app.set('views', '/opt/app/views');
app.set('view engine', 'ejs');
app.use('/dist/bootstrap', express.static('/app/public'));
app.use(router.router);
app.use(express.static('/app/public'));
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

View File

@@ -0,0 +1,14 @@
import { Request, Response } from 'express';
import fooService from '../services/foo.service';
function getFoo(req: Request, res: Response) {
res.json({
foo: true,
msg: fooService.getFooDetails(),
data: req.body,
});
}
export default {
getFoo,
};

8
app/src/router.ts Normal file
View File

@@ -0,0 +1,8 @@
import { Router } from 'express';
import fooController from './controllers/foo.controller';
const router = Router();
router.get('/foo', fooController.getFoo);
export default { router };

View File

@@ -0,0 +1,7 @@
function getFooDetails() {
return 'foo';
}
export default {
getFooDetails,
};