mirror of
https://github.com/KeyZox71/knl_meowscendence.git
synced 2025-08-14 12:32:54 +02:00
「🏗️」 wip: dev.js -> start.js and working user api docker
This commit is contained in:
@ -8,3 +8,6 @@ node_modules/
|
|||||||
# useless files in the docker
|
# useless files in the docker
|
||||||
*.md
|
*.md
|
||||||
docker/
|
docker/
|
||||||
|
|
||||||
|
# PLEASE NO
|
||||||
|
.env
|
||||||
|
@ -6,5 +6,15 @@ services:
|
|||||||
# environment:
|
# environment:
|
||||||
# - euuuh
|
# - euuuh
|
||||||
user-api:
|
user-api:
|
||||||
image:
|
build:
|
||||||
cmd:
|
dockerfile: docker/user-api/Dockerfile
|
||||||
|
context: ..
|
||||||
|
networks:
|
||||||
|
- transcendence
|
||||||
|
ports:
|
||||||
|
- 3000:3000
|
||||||
|
|
||||||
|
networks:
|
||||||
|
transcendence:
|
||||||
|
external: false
|
||||||
|
name: transcendence
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
FROM node-base
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
ENV API_TARGET="user"
|
||||||
|
CMD [ "node", "/app/src/start.js" ]
|
||||||
|
46
src/start.js
Normal file
46
src/start.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import Fastify from 'fastify';
|
||||||
|
import authApi from './api/auth/default.js';
|
||||||
|
import userApi from './api/user/default.js';
|
||||||
|
|
||||||
|
const loggerOption = {
|
||||||
|
transport: {
|
||||||
|
target: 'pino-pretty',
|
||||||
|
options: {
|
||||||
|
colorize: true,
|
||||||
|
translateTime: 'HH:MM:ss',
|
||||||
|
ignore: 'pid,hostname'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
async function start() {
|
||||||
|
const target = process.env.API_TARGET || 'all';
|
||||||
|
|
||||||
|
if (target === 'auth' || target === 'all') {
|
||||||
|
const auth = Fastify({ logger: loggerOption });
|
||||||
|
auth.register(authApi);
|
||||||
|
if (target !== 'all') {
|
||||||
|
await auth.listen({ port: 3000, host: '0.0.0.0' });
|
||||||
|
console.log('Auth API listening on http://0.0.0.0:3000');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await auth.listen({ port: 3001, host: '127.0.0.1'});
|
||||||
|
console.log('Auth API listening on http://localhost:3001');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target === 'user' || target === 'all') {
|
||||||
|
const user = Fastify({ logger: loggerOption });
|
||||||
|
user.register(userApi);
|
||||||
|
if (target !== 'all') {
|
||||||
|
await user.listen({ port: 3000, host: '0.0.0.0' });
|
||||||
|
console.log('User API listening on http://0.0.0.0:3000');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await user.listen({ port: 3002, host: '127.0.0.1'});
|
||||||
|
console.log('User API listening on http://localhost:3002');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
start().catch(console.error);
|
Reference in New Issue
Block a user