generated from fionn/ts-template
Initial commit
This commit is contained in:
31
backend/.eslintrc.json
Normal file
31
backend/.eslintrc.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"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": {
|
||||
"eol-last": [
|
||||
"error",
|
||||
"always"
|
||||
]
|
||||
}
|
||||
}
|
||||
5647
backend/package-lock.json
generated
Normal file
5647
backend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
33
backend/package.json
Normal file
33
backend/package.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "app",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"predev": "npm install && rimraf dist/*",
|
||||
"start": "node --inspect=0.0.0.0:9229 --es-module-specifier-resolution=node dist/app.js",
|
||||
"dev": "tsc-watch --onSuccess \"npm run start\" --onFailure \"echo WHOOPS! Server compilation failed\""
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "Fionn Sperath",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"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"
|
||||
}
|
||||
}
|
||||
26
backend/src/app.ts
Normal file
26
backend/src/app.ts
Normal 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}`,
|
||||
);
|
||||
});
|
||||
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,
|
||||
};
|
||||
14
backend/src/router.ts
Normal file
14
backend/src/router.ts
Normal 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 };
|
||||
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,
|
||||
};
|
||||
22
backend/tsconfig.json
Normal file
22
backend/tsconfig.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"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",
|
||||
},
|
||||
"watchOptions": {
|
||||
"watchFile": "fixedpollinginterval"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user