Add Express service with health endpoint
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
node_modules
|
||||||
|
dist
|
||||||
1180
package-lock.json
generated
Normal file
1180
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
13
package.json
13
package.json
@@ -2,8 +2,19 @@
|
|||||||
"name": "demo-repo",
|
"name": "demo-repo",
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"description": "A sample package.json",
|
"description": "A sample package.json",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "ts-node src/index.ts",
|
||||||
|
"build": "tsc",
|
||||||
|
"start": "node dist/index.js"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@primer/css": "17.0.1"
|
"@primer/css": "17.0.1",
|
||||||
|
"express": "^4.19.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/express": "^4.17.21",
|
||||||
|
"ts-node": "^10.9.2",
|
||||||
|
"typescript": "^5.6.2"
|
||||||
},
|
},
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
|||||||
17
src/index.ts
Normal file
17
src/index.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import express from "express";
|
||||||
|
import path from "path";
|
||||||
|
import health from "./routes/health";
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
app.use(health);
|
||||||
|
|
||||||
|
app.get("/", (_req, res) => {
|
||||||
|
res.sendFile(path.join(__dirname, "../index.html"));
|
||||||
|
});
|
||||||
|
|
||||||
|
const port = Number(process.env.PORT) || 8080;
|
||||||
|
|
||||||
|
app.listen(port, "0.0.0.0", () => {
|
||||||
|
console.log(`[blackroad-os-demo] listening on http://0.0.0.0:${port}`);
|
||||||
|
});
|
||||||
9
src/routes/health.ts
Normal file
9
src/routes/health.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { Router } from "express";
|
||||||
|
|
||||||
|
const r = Router();
|
||||||
|
|
||||||
|
r.get("/health", (_req, res) => {
|
||||||
|
res.status(200).json({ status: "ok", service: "blackroad-os-demo" });
|
||||||
|
});
|
||||||
|
|
||||||
|
export default r;
|
||||||
13
tsconfig.json
Normal file
13
tsconfig.json
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2019",
|
||||||
|
"module": "CommonJS",
|
||||||
|
"outDir": "dist",
|
||||||
|
"rootDir": "src",
|
||||||
|
"strict": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"skipLibCheck": true
|
||||||
|
},
|
||||||
|
"include": ["src/**/*"]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user