单人单台扫描终端支持10分钟内完成≥50个牙列或牙体雕刻作品高速扫描采集
This commit is contained in:
40
server.cjs
Normal file
40
server.cjs
Normal file
@@ -0,0 +1,40 @@
|
||||
const http = require("http");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const root = __dirname;
|
||||
const port = Number(process.env.PORT || 4173);
|
||||
const types = {
|
||||
".html": "text/html;charset=utf-8",
|
||||
".css": "text/css;charset=utf-8",
|
||||
".js": "text/javascript;charset=utf-8",
|
||||
};
|
||||
|
||||
const server = http.createServer((request, response) => {
|
||||
const url = new URL(request.url, `http://localhost:${port}`);
|
||||
const requestedPath = url.pathname === "/" ? "index.html" : url.pathname.slice(1);
|
||||
const filePath = path.resolve(root, requestedPath);
|
||||
|
||||
if (!filePath.startsWith(root)) {
|
||||
response.writeHead(403);
|
||||
response.end("Forbidden");
|
||||
return;
|
||||
}
|
||||
|
||||
fs.readFile(filePath, (error, buffer) => {
|
||||
if (error) {
|
||||
response.writeHead(404);
|
||||
response.end("Not found");
|
||||
return;
|
||||
}
|
||||
|
||||
response.writeHead(200, {
|
||||
"Content-Type": types[path.extname(filePath)] || "application/octet-stream",
|
||||
});
|
||||
response.end(buffer);
|
||||
});
|
||||
});
|
||||
|
||||
server.listen(port, "127.0.0.1", () => {
|
||||
console.log(`Dental 3D demo: http://localhost:${port}`);
|
||||
});
|
||||
Reference in New Issue
Block a user