Merge remote-tracking branch 'origin/api' into backend

This commit is contained in:
j-weissen 2022-12-06 08:10:33 +01:00
commit f0b379a379
6 changed files with 1950 additions and 0 deletions

View file

@ -0,0 +1,9 @@
FROM node:18
COPY ./* /app/
WORKDIR /app
RUN npm install
ENTRYPOINT ["npm", "run"]
CMD ["prod"]

1857
backend/api/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

26
backend/api/package.json Normal file
View file

@ -0,0 +1,26 @@
{
"name": "express-api",
"version": "1.0.0",
"description": "",
"type": "module",
"scripts": {
"build": "tsc",
"dev": "ts-node-esm src/app.ts",
"prod": "tsc && node build/app.ts"
},
"author": "jweissen",
"license": "ISC",
"dependencies": {
"body-parser": "^1.20.1",
"express": "^4.18.2",
"helmet": "^6.0.1",
"morgan": "^1.10.0",
"pg-promise": "^10.15.4",
"ts-node": "^10.9.1",
"typescript": "^4.9.3"
},
"devDependencies": {
"@types/express": "^4.17.14",
"@types/node": "^18.11.9"
}
}

31
backend/api/src/app.ts Normal file
View file

@ -0,0 +1,31 @@
import express from 'express';
import pgPromise from "pg-promise";
import helmet from "helmet";
import bodyParser from "body-parser";
import morgan from 'morgan';
const app = express()
const port = 3000
app.use(helmet())
// configure & use logger
let morganFormatted = morgan('[:date[iso]] :method :url - :status')
app.use(morganFormatted);
// init database connection
const pgp = pgPromise({});
const db = pgp('postgres://postgres:postgres@localhost:5432/rr')
app.get('/highscore', async (req, res) => {
let data = await db.any(
'SELECT * FROM lb_highscore;'
)
res.send(data)
})
app.listen(port, () => {
morganFormatted.log(`Server started at http://localhost:3000`);
})

View file

@ -0,0 +1,16 @@
import * as express from 'express';
import * as bodyParser from "body-parser";
let router = express.Router();
router.use(bodyParser.json())
router.get('/helloworld', (req, res) => {
res.json({message: "Hello World!"})
})
router.post('/echo', (req, res) => {
res.json(req.body)
})
module.exports = router

11
backend/api/tsconfig.json Normal file
View file

@ -0,0 +1,11 @@
{
"compilerOptions": {
"esModuleInterop": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"target": "ES2020",
"sourceMap": true,
"outDir": "build/"
},
"include": ["src/**/*"]
}