import http from 'node:http';
import fs from 'node:fs';
import path from 'node:path';
import {fileURLToPath} from 'node:url';
const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
const types={'.html':'text/html','.js':'text/javascript','.svg':'image/svg+xml','.json':'application/json','.css':'text/css','.woff2':'font/woff2','.png':'image/png','.webp':'image/webp','.md':'text/plain','.csv':'text/csv','.zip':'application/zip'};
http.createServer((req,res)=>{const pathname=decodeURIComponent(new URL(req.url,'http://localhost').pathname),file=path.resolve(root,'.'+(pathname==='/'?'/index.html':pathname));if(!file.startsWith(root+path.sep)){res.writeHead(403);res.end();return;}try{const stat=fs.statSync(file);if(!stat.isFile())throw new Error('Not a file');res.writeHead(200,{'Content-Type':types[path.extname(file)]||'application/octet-stream','Cache-Control':'no-store'});fs.createReadStream(file).pipe(res);}catch{res.writeHead(404);res.end('Not found');}}).listen(4177,'127.0.0.1',()=>console.log('Ankra redesign preview: http://127.0.0.1:4177'));
