Step 1 migration: add API service and dedicated PostgreSQL
This commit is contained in:
7
api/Dockerfile
Normal file
7
api/Dockerfile
Normal 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
32
api/server.js
Normal 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}`);
|
||||
});
|
||||
Reference in New Issue
Block a user