diff --git a/assets/img/background.jpg b/assets/img/background.jpg new file mode 100644 index 0000000..b8b10e4 Binary files /dev/null and b/assets/img/background.jpg differ diff --git a/assets/img/favicon.png b/assets/img/favicon.png new file mode 100644 index 0000000..29df44d Binary files /dev/null and b/assets/img/favicon.png differ diff --git a/assets/img/title.png b/assets/img/title.png new file mode 100644 index 0000000..0b616cd Binary files /dev/null and b/assets/img/title.png differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..3a75e09 --- /dev/null +++ b/index.html @@ -0,0 +1,110 @@ + + + + + + + + + Document + + + + +
+
+
+ + 答案之书 +
+
+
+
点击查看答案
+
+
+ +
+
+
+
+
+
+
+

+ - 仅供娱乐,请勿当真 - +

+
+ + + + + \ No newline at end of file diff --git a/index.js b/index.js index 7c2a987..abee62c 100644 --- a/index.js +++ b/index.js @@ -133,11 +133,20 @@ const server = createServer(async function (req, res) { res.end('try again later') return } - res.writeHeader(200, { 'Content-Type': 'text/plain;charset=utf-8' }); // res.writeHeader(200, { 'Content-Type': 'text/html;charset=utf-8' }); + if (req.url.startsWith("/assets")) { + // 直接返回静态文件 + let image = fs.readFileSync(`.${req.url}`); + res.writeHeader(200, { 'Content-Type': 'image/jpeg' }); + res.end(image); + return; + } + switch (req.url) { // http://localhost:3000/api/get case '/api/get': + // api 接口 + res.writeHeader(200, { 'Content-Type': 'text/plain;charset=utf-8' }); var resultArr = await getOne(); var result = resultArr[0]; // console.log(result); @@ -147,7 +156,15 @@ const server = createServer(async function (req, res) { data: result, })) break; + case '/': + // html 页面 + let html = fs.readFileSync("./index.html"); + res.writeHeader(200, { 'Content-Type': 'text/html;charset=utf-8' }); + res.end(html); + break; default: + // 404 报错 + console.log(req.url); res.end(JSON.stringify({ code: 404, msg: "Not Found", @@ -155,7 +172,6 @@ const server = createServer(async function (req, res) { })) break; } - // console.log(Object.keys(req)); console.log(req.url); }) server.listen(3000)