Files
workspace/code/fms/.tmp-server.js
T
2026-08-27 23:06:36 +08:00

21 lines
629 B
JavaScript

const http = require('http')
const fs = require('fs')
const path = require('path')
const root = 'd:/workspace/code/fms'
http
.createServer((req, res) => {
const urlPath = req.url === '/' ? '/.tmp-dnd-test.html' : decodeURIComponent(req.url.split('?')[0])
const fp = path.join(root, urlPath)
fs.readFile(fp, (err, data) => {
if (err) {
res.writeHead(404)
res.end('nf')
return
}
res.writeHead(200, { 'Content-Type': fp.endsWith('.html') ? 'text/html; charset=utf-8' : 'text/plain' })
res.end(data)
})
})
.listen(8090, '127.0.0.1')
console.log('server on 8090')