-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move built-in HTTP pages to separeted file
- Loading branch information
Showing
2 changed files
with
28 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { readFile } from 'node:fs/promises' | ||
import { join } from 'node:path' | ||
|
||
let hello | ||
async function readHello() { | ||
if (!hello) { | ||
hello = await readFile(join(import.meta.dirname, '..', 'hello.html')) | ||
Check failure on line 7 in add-http-pages/index.js
|
||
} | ||
return hello | ||
} | ||
|
||
export function addHttpPages(server) { | ||
if (!server.options.disableHttpServer) { | ||
server.http('GET', '/', async (req, res) => { | ||
let data = await readHello() | ||
res.writeHead(200, { 'Content-Type': 'text/html' }) | ||
res.end(data) | ||
}) | ||
server.http('GET', '/health', (req, res) => { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }) | ||
res.end('Logux Server: OK\n') | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters