初始化简单写作项目
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
const http = require("http");
|
||||
function req(path, method, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const body = data ? JSON.stringify(data) : null;
|
||||
const headers = { "Content-Type": "application/json" };
|
||||
if (body) headers["Content-Length"] = Buffer.byteLength(body);
|
||||
const r = http.request({ host: "localhost", port: 8080, path, method, headers }, (res) => {
|
||||
let d = ""; res.on("data", (c) => (d += c)); res.on("end", () => resolve({ status: res.statusCode, body: d.slice(0, 200) }));
|
||||
});
|
||||
r.on("error", reject);
|
||||
if (body) r.write(body);
|
||||
r.end();
|
||||
});
|
||||
}
|
||||
(async () => {
|
||||
// 静态页面
|
||||
const page = await req("/", "GET");
|
||||
console.log("GET / ->", page.status, page.body.includes("简单写作") ? "(含页面)" : "");
|
||||
const js = await req("/app.js", "GET");
|
||||
console.log("GET /app.js ->", js.status);
|
||||
// WebDAV 代理(用一个无效地址,验证代理在运行并能正确返回错误而非崩溃)
|
||||
const wd = await req("/api/webdav/propfind", "POST", { base: "https://invalid.invalid.example/", path: "x.json", user: "u", pass: "p" });
|
||||
console.log("webdav proxy ->", wd.status, "(代理已响应,预期非 200)");
|
||||
})();
|
||||
Reference in New Issue
Block a user