Step 1 migration: add API service and dedicated PostgreSQL

This commit is contained in:
Ponte
2026-02-11 14:53:13 +01:00
parent 8e96541fb1
commit aae5471862
5 changed files with 92 additions and 1 deletions

7
api/Dockerfile Normal file
View File

@@ -0,0 +1,7 @@
FROM node:20-alpine
WORKDIR /app
COPY api/server.js ./server.js
EXPOSE 3001
CMD ["node", "server.js"]

32
api/server.js Normal file
View File

@@ -0,0 +1,32 @@
const http = require("http");
const port = Number(process.env.API_INTERNAL_PORT || 3001);
const serviceName = process.env.SERVICE_NAME || "video-games-api";
function sendJson(response, statusCode, payload) {
response.writeHead(statusCode, { "Content-Type": "application/json; charset=utf-8" });
response.end(JSON.stringify(payload));
}
const server = http.createServer((request, response) => {
const url = new URL(request.url || "/", `http://${request.headers.host || "localhost"}`);
if (request.method === "GET" && url.pathname === "/health") {
sendJson(response, 200, {
status: "ok",
service: serviceName,
timestamp: new Date().toISOString(),
});
return;
}
sendJson(response, 404, {
status: "not_found",
message: "Route not found",
});
});
server.listen(port, "0.0.0.0", () => {
// Keep startup logs minimal and readable in docker compose logs.
console.log(`${serviceName} listening on port ${port}`);
});