更新采购订单、发货、合同查询、盘点、入库和配置文件,新增零改单和文档
This commit is contained in:
22
docs/preview-server.js
Normal file
22
docs/preview-server.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const http = require('http');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const root = __dirname;
|
||||
const types = { '.html': 'text/html; charset=utf-8', '.png': 'image/png', '.css': 'text/css; charset=utf-8', '.js': 'text/javascript; charset=utf-8', '.md': 'text/plain; charset=utf-8' };
|
||||
const server = http.createServer((req, res) => {
|
||||
try {
|
||||
const url = new URL(req.url, 'http://127.0.0.1:18765');
|
||||
const rel = decodeURIComponent(url.pathname).replace(/^\/+/, '');
|
||||
const filePath = path.resolve(root, rel);
|
||||
if (!filePath.startsWith(path.resolve(root))) {
|
||||
res.writeHead(403); res.end('Forbidden'); return;
|
||||
}
|
||||
fs.readFile(filePath, (err, data) => {
|
||||
if (err) { res.writeHead(404); res.end('Not found: ' + filePath); return; }
|
||||
res.writeHead(200, { 'Content-Type': types[path.extname(filePath).toLowerCase()] || 'application/octet-stream' });
|
||||
res.end(data);
|
||||
});
|
||||
} catch (e) { res.writeHead(500); res.end(String(e)); }
|
||||
});
|
||||
server.listen(18765, '127.0.0.1', () => console.log('preview server on 18765'));
|
||||
setInterval(() => {}, 1000);
|
||||
Reference in New Issue
Block a user