mv app to backend
This commit is contained in:
26
backend/.eslintrc.json
Normal file
26
backend/.eslintrc.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"env": {
|
||||
"es2021": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": [
|
||||
"airbnb-typescript/base",
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended"
|
||||
],
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": [
|
||||
"@typescript-eslint",
|
||||
"import",
|
||||
"promise"
|
||||
],
|
||||
"overrides": [],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": "latest",
|
||||
"sourceType": "module",
|
||||
"project": "./tsconfig.json"
|
||||
},
|
||||
"rules": {}
|
||||
}
|
||||
5849
backend/package-lock.json
generated
Normal file
5849
backend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
34
backend/package.json
Normal file
34
backend/package.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "app",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"prerun:dev": "npm install && rimraf dist/*",
|
||||
"run:prod": "node --inspect=0.0.0.0:9229 --es-module-specifier-resolution=node dist/app.js",
|
||||
"run:dev": "tsc-watch --onSuccess \"npm run run:prod\" --onFailure \"echo WHOOPS! Server compilation failed\""
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "Fionn Sperath",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"ejs-mate": "^4.0.0",
|
||||
"express": "^4.18.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.13",
|
||||
"@types/node": "^18.7.6",
|
||||
"@typescript-eslint/eslint-plugin": "^5.38.1",
|
||||
"@typescript-eslint/parser": "^5.38.1",
|
||||
"eslint": "^8.23.1",
|
||||
"eslint-config-airbnb-typescript": "^17.0.0",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-plugin-n": "^15.2.5",
|
||||
"eslint-plugin-promise": "^6.0.1",
|
||||
"rimraf": "^3.0.2",
|
||||
"tsc-watch": "^5.0.3",
|
||||
"typescript": "^4.7.4"
|
||||
}
|
||||
}
|
||||
34
backend/src/app.ts
Normal file
34
backend/src/app.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
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(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'));
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
app.use((err, req: Request, res: Response, next: NextFunction) => {
|
||||
// 404
|
||||
res.render('error');
|
||||
});
|
||||
|
||||
app.listen(PORT, () => {
|
||||
console.log(
|
||||
`application is listening on port ${PORT}`,
|
||||
);
|
||||
});
|
||||
14
backend/src/controllers/foo.controller.ts
Normal file
14
backend/src/controllers/foo.controller.ts
Normal 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
backend/src/router.ts
Normal file
8
backend/src/router.ts
Normal 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 };
|
||||
7
backend/src/services/foo.service.ts
Normal file
7
backend/src/services/foo.service.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
function getFooDetails() {
|
||||
return 'foo';
|
||||
}
|
||||
|
||||
export default {
|
||||
getFooDetails,
|
||||
};
|
||||
19
backend/tsconfig.json
Normal file
19
backend/tsconfig.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compileOnSave": false,
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"module": "ES2022",
|
||||
"target": "ES2022",
|
||||
"lib": [
|
||||
"ES2022"
|
||||
],
|
||||
"sourceMap": true,
|
||||
"strictNullChecks": true,
|
||||
"noImplicitAny": false,
|
||||
"preserveConstEnums": true,
|
||||
"removeComments": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"esModuleInterop": true,
|
||||
"moduleResolution": "Node"
|
||||
}
|
||||
}
|
||||
3
backend/views/error.ejs
Normal file
3
backend/views/error.ejs
Normal file
@@ -0,0 +1,3 @@
|
||||
<% layout('layout') -%>
|
||||
|
||||
Oops! Something went wrong :(
|
||||
15
backend/views/layout.ejs
Normal file
15
backend/views/layout.ejs
Normal file
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>New App 😀</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<%- body -%>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user