feat: add TypeScript server skeleton

This commit is contained in:
2026-06-07 12:18:00 +02:00
parent 28c91a4b0e
commit cc5a567335
4 changed files with 66 additions and 0 deletions

14
src/index.ts Normal file
View File

@@ -0,0 +1,14 @@
import { createServer } from "node:http";
import { env } from "./shared/env.js";
import { createRequestHandler } from "./server/request-handler.js";
const handler = createRequestHandler();
const server = createServer((req, res) => {
void handler(req, res);
});
server.listen(env.port, env.host, () => {
console.log(`mapy-mg listening on http://${env.host}:${env.port}`);
});

View File

@@ -0,0 +1,21 @@
import type { IncomingMessage, ServerResponse } from "node:http";
export function createRequestHandler() {
return async function handleRequest(_req: IncomingMessage, res: ServerResponse) {
res.statusCode = 200;
res.setHeader("content-type", "application/json; charset=utf-8");
res.end(
JSON.stringify({
name: "mapy-mg",
status: "ok",
features: [
"photo upload",
"EXIF location extraction",
"map markers",
"route preview"
]
})
);
};
}

15
src/shared/env.ts Normal file
View File

@@ -0,0 +1,15 @@
function parsePort(value: string | undefined): number {
const port = Number(value ?? "3000");
if (!Number.isInteger(port) || port < 1 || port > 65535) {
throw new Error("PORT must be an integer between 1 and 65535");
}
return port;
}
export const env = {
host: process.env.HOST ?? "0.0.0.0",
port: parsePort(process.env.PORT)
} as const;

16
tsconfig.json Normal file
View File

@@ -0,0 +1,16 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"rootDir": "src",
"outDir": "dist",
"strict": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
"esModuleInterop": true,
"skipLibCheck": true
},
"include": ["src/**/*.ts"]
}