forked from coffee-cup-app/e2e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
41 lines (33 loc) · 997 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import fastify from "fastify";
import { text } from "./hello";
// Get all environment variables that start with RAILWAY_
const railwayVars: Record<string, string> = {};
Object.entries(process.env)
.filter(
([key, value]) =>
key.startsWith("RAILWAY_") && value != null && value.trim() !== ""
)
.forEach(([key, value]) => {
railwayVars[key] = value ?? "";
});
if (Object.keys(railwayVars).length > 0) {
console.log(JSON.stringify(railwayVars, null, 2));
}
const server = fastify();
server.get("/", async (request, reply) => {
reply.code(200).send({ message: text, ...railwayVars });
});
const start = async () => {
try {
const port = parseInt(process.env.PORT ?? "9999");
const host = "0.0.0.0";
await server.listen({ port, host });
console.log(`Server started at http://${host}:${port}`);
console.log(`Text: ${text}`);
} catch (err) {
console.log("Fastify failed to start");
console.error(err);
process.exit(1);
}
};
start();