feat: initialize VitePress CMS
This commit is contained in:
26
server/http.mjs
Normal file
26
server/http.mjs
Normal file
@@ -0,0 +1,26 @@
|
||||
export function json(response, status, payload, headers = {}) {
|
||||
response.writeHead(status, {
|
||||
"Content-Type": "application/json; charset=utf-8",
|
||||
...headers,
|
||||
});
|
||||
response.end(JSON.stringify(payload));
|
||||
}
|
||||
|
||||
export function redirect(response, location, headers = {}) {
|
||||
response.writeHead(302, {
|
||||
Location: location,
|
||||
...headers,
|
||||
});
|
||||
response.end();
|
||||
}
|
||||
|
||||
export function readBody(request) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let body = "";
|
||||
request.on("data", (chunk) => {
|
||||
body += chunk;
|
||||
});
|
||||
request.on("end", () => resolve(body));
|
||||
request.on("error", reject);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user