serve hello world on wildcard uri
This commit is contained in:
parent
5d17994c6b
commit
2d5ee6cb61
47
src/main.ts
47
src/main.ts
|
@ -1,17 +1,54 @@
|
|||
import fastify from "fastify";
|
||||
|
||||
const server = fastify();
|
||||
const bindHost = "0.0.0.0";
|
||||
const port = 8080;
|
||||
const defaultFile = "index.html";
|
||||
const errorFile = "404.html";
|
||||
const allMethods = [
|
||||
"DELETE",
|
||||
"GET",
|
||||
"HEAD",
|
||||
"PATCH",
|
||||
"POST",
|
||||
"PUT",
|
||||
"OPTIONS",
|
||||
"SEARCH",
|
||||
"TRACE",
|
||||
"PROPFIND",
|
||||
"PROPPATCH",
|
||||
"MKCOL",
|
||||
"COPY",
|
||||
"MOVE",
|
||||
"LOCK",
|
||||
"UNLOCK",
|
||||
];
|
||||
|
||||
server.get("/", async () => {
|
||||
return "Hello, World!\n";
|
||||
server.route({
|
||||
method: "GET",
|
||||
url: "/healthz",
|
||||
schema: {
|
||||
response: {
|
||||
200: {
|
||||
type: "string",
|
||||
pattern: "^OK\n$",
|
||||
},
|
||||
},
|
||||
},
|
||||
handler: async () => {
|
||||
return "OK\n";
|
||||
},
|
||||
});
|
||||
|
||||
server.get("/healthz", async () => {
|
||||
return "OK\n";
|
||||
server.route({
|
||||
method: allMethods as any,
|
||||
url: "/*",
|
||||
handler: async (request, reply) => {
|
||||
return "Hello World\n";
|
||||
},
|
||||
});
|
||||
|
||||
server.listen({ host: "0.0.0.0", port }, (err) => {
|
||||
server.listen({ host: bindHost, port }, (err) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
|
|
Loading…
Reference in a new issue