everything dockerized
This commit is contained in:
parent
f0b379a379
commit
529da45219
6 changed files with 62 additions and 14 deletions
7
.env.example
Normal file
7
.env.example
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
POSTGRES_PORT=3000
|
||||
EXPRESS_PORT=5432
|
||||
|
||||
POSTGRES_USER=postgres
|
||||
POSTGRES_PASSWORD=postgres
|
||||
POSTGRES_DB=rr
|
||||
|
||||
|
|
@ -1,9 +1,11 @@
|
|||
FROM node:18
|
||||
|
||||
COPY ./* /app/
|
||||
COPY . /app
|
||||
WORKDIR /app
|
||||
|
||||
RUN npm install
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
ENTRYPOINT ["npm", "run"]
|
||||
CMD ["prod"]
|
||||
19
backend/api/package-lock.json
generated
19
backend/api/package-lock.json
generated
|
|
@ -19,6 +19,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.14",
|
||||
"@types/morgan": "^1.9.3",
|
||||
"@types/node": "^18.11.9"
|
||||
}
|
||||
},
|
||||
|
|
@ -123,6 +124,15 @@
|
|||
"integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/morgan": {
|
||||
"version": "1.9.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/morgan/-/morgan-1.9.3.tgz",
|
||||
"integrity": "sha512-BiLcfVqGBZCyNCnCH3F4o2GmDLrpy0HeBVnNlyZG4fo88ZiE9SoiBe3C+2ezuwbjlEyT+PDZ17//TAlRxAn75Q==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "18.11.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.9.tgz",
|
||||
|
|
@ -1166,6 +1176,15 @@
|
|||
"integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/morgan": {
|
||||
"version": "1.9.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/morgan/-/morgan-1.9.3.tgz",
|
||||
"integrity": "sha512-BiLcfVqGBZCyNCnCH3F4o2GmDLrpy0HeBVnNlyZG4fo88ZiE9SoiBe3C+2ezuwbjlEyT+PDZ17//TAlRxAn75Q==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "18.11.9",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.9.tgz",
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
"scripts": {
|
||||
"build": "tsc",
|
||||
"dev": "ts-node-esm src/app.ts",
|
||||
"prod": "tsc && node build/app.ts"
|
||||
"prod": "tsc && node build/app.js"
|
||||
},
|
||||
"author": "jweissen",
|
||||
"license": "ISC",
|
||||
|
|
@ -21,6 +21,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.14",
|
||||
"@types/morgan": "^1.9.3",
|
||||
"@types/node": "^18.11.9"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,16 +16,29 @@ app.use(morganFormatted);
|
|||
|
||||
// init database connection
|
||||
const pgp = pgPromise({});
|
||||
const db = pgp('postgres://postgres:postgres@localhost:5432/rr')
|
||||
const db = pgp('postgres://postgres:postgres@db:5432/rr')
|
||||
|
||||
app.get('/helloworld', (req, res) => {
|
||||
res.json({message: "Hello World!"})
|
||||
})
|
||||
|
||||
app.get('/highscore', async (req, res) => {
|
||||
let data = await db.any(
|
||||
'SELECT * FROM lb_highscore;'
|
||||
let data = await dbQueryCatcher(async () =>
|
||||
await db.manyOrNone('SELECT * FROM lb_highscore;')
|
||||
)
|
||||
res.send(data)
|
||||
res.json(data)
|
||||
})
|
||||
|
||||
async function dbQueryCatcher(request): Promise<any> {
|
||||
let data;
|
||||
try {
|
||||
data = await request();
|
||||
} catch (e) {
|
||||
console.log((e as Error).message)
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
app.listen(port, () => {
|
||||
morganFormatted.log(`Server started at http://localhost:3000`);
|
||||
console.log(`Server started at http://localhost:3000`);
|
||||
})
|
||||
|
|
@ -5,11 +5,17 @@ services:
|
|||
build: backend/db
|
||||
container_name: postgres-db
|
||||
environment:
|
||||
POSTGRES_DB: rr
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
POSTGRES_DB: ${POSTGRES_DB}
|
||||
POSTGRES_USER: ${POSTGRES_USER}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
ports:
|
||||
- "5432:5432"
|
||||
- "${POSTGRES_PORT}:5432"
|
||||
volumes:
|
||||
- ./backend/pgdata:/var/lib/postgresql/data
|
||||
|
||||
api:
|
||||
build: backend/api
|
||||
container_name: express-api
|
||||
ports:
|
||||
- "${EXPRESS_PORT}:3000"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue