Initial commit

This commit is contained in:
2023-03-10 12:43:00 -06:00
commit f81e2c9324
30 changed files with 13214 additions and 0 deletions

26
backend/src/app.ts Normal file
View File

@@ -0,0 +1,26 @@
import express, { NextFunction, Request, Response } from 'express';
import router from './router';
const { PORT = 3000 } = process.env;
const app = express();
app.use('/api', router.router);
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) => {
console.log('err', err);
// 500
res.status(500).json({ msg: 'an error occurred' });
});
app.listen(PORT, () => {
console.log(
`application is listening on port ${PORT}`,
);
});

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,
};

14
backend/src/router.ts Normal file
View File

@@ -0,0 +1,14 @@
import { Request, Response, Router } from 'express';
import fooController from './controllers/foo.controller';
const router = Router();
router.get('/foo', fooController.getFoo);
// aaaaa
router.use((req: Request, res: Response) => {
// 404
res.status(404).json({ msg: 'the requested resource could not be found' });
});
export default { router };

View File

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