|
1 | 1 | // Import Node.js Dependencies |
2 | 2 | import stream from "node:stream"; |
| 3 | +import type { |
| 4 | + IncomingMessage, |
| 5 | + ServerResponse |
| 6 | +} from "node:http"; |
3 | 7 |
|
4 | 8 | // Import Third-party Dependencies |
5 | | -import send from "@polka/send-type"; |
6 | | -import { getManifest, lazyFetchFlagFile, getFlags } from "@nodesecure/flags"; |
7 | | -import type { Request, Response } from "express-serve-static-core"; |
| 9 | +import { |
| 10 | + getManifest, |
| 11 | + lazyFetchFlagFile, |
| 12 | + getFlags |
| 13 | +} from "@nodesecure/flags"; |
| 14 | + |
| 15 | +// Import Internal Dependencies |
| 16 | +import { send } from "./util/send.ts"; |
8 | 17 |
|
9 | 18 | // CONSTANTS |
10 | 19 | const kNodeSecureFlags = getFlags(); |
11 | 20 |
|
12 | | -export function getAll(_req, res) { |
13 | | - send(res, 200, getManifest()); |
| 21 | +export function getAll( |
| 22 | + _req: IncomingMessage, |
| 23 | + res: ServerResponse |
| 24 | +) { |
| 25 | + send(res, getManifest()); |
14 | 26 | } |
15 | 27 |
|
16 | | -export function get(req: Request, res: Response) { |
17 | | - if (req.params.title !== "hasDuplicate" && !kNodeSecureFlags.has(req.params.title)) { |
18 | | - return send(res, 404, { error: "Not Found" }); |
| 28 | +export function get( |
| 29 | + _: IncomingMessage, |
| 30 | + res: ServerResponse, |
| 31 | + params: Record<string, string | undefined> |
| 32 | +) { |
| 33 | + const { title } = params; |
| 34 | + if (!title) { |
| 35 | + return send( |
| 36 | + res, |
| 37 | + { error: "Title is missing." }, |
| 38 | + { code: 400 } |
| 39 | + ); |
| 40 | + } |
| 41 | + |
| 42 | + if ( |
| 43 | + title !== "hasDuplicate" && |
| 44 | + !kNodeSecureFlags.has(title) |
| 45 | + ) { |
| 46 | + return send( |
| 47 | + res, |
| 48 | + { error: "Not Found" }, |
| 49 | + { code: 404 } |
| 50 | + ); |
19 | 51 | } |
20 | 52 |
|
21 | 53 | res.writeHead(200, { "Content-Type": "text/html" }); |
22 | 54 |
|
23 | | - return stream.pipeline(lazyFetchFlagFile(req.params.title), res, (err) => { |
| 55 | + return stream.pipeline(lazyFetchFlagFile(title), res, (err) => { |
24 | 56 | if (err) { |
25 | 57 | console.error(err); |
26 | 58 | } |
|
0 commit comments