feat: add hex trail puzzle, level editor, and visual design guide
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import http from 'node:http';
|
||||
import { readFile, stat } from 'node:fs/promises';
|
||||
import { resolve, extname, sep } from 'node:path';
|
||||
const root=resolve(process.argv.includes('--dist')?'dist':'.');
|
||||
const port=Number(process.env.PORT||4173);
|
||||
const types={'.html':'text/html; charset=utf-8','.js':'text/javascript; charset=utf-8','.css':'text/css; charset=utf-8','.json':'application/json; charset=utf-8','.svg':'image/svg+xml','.png':'image/png'};
|
||||
http.createServer(async(req,res)=>{
|
||||
try {
|
||||
const url=new URL(req.url,'http://localhost');
|
||||
const path=resolve(root,'.'+decodeURIComponent(url.pathname==='/'?'/index.html':url.pathname));
|
||||
if(path!==root&&!path.startsWith(root+sep)){res.writeHead(403);res.end('Forbidden');return;}
|
||||
if(!(await stat(path)).isFile()){res.writeHead(404);res.end('Not found');return;}
|
||||
const body=await readFile(path);res.writeHead(200,{'Content-Type':types[extname(path)]||'application/octet-stream','Cache-Control':'no-cache'});res.end(body);
|
||||
}catch{res.writeHead(404);res.end('Not found');}
|
||||
}).listen(port,'0.0.0.0',()=>console.log(`HEX TRAILS http://localhost:${port}`));
|
||||
Reference in New Issue
Block a user