Files
NumberSwipe_New/campaign-200/tools/serve-mobile.mjs
T

17 lines
954 B
JavaScript

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 host='192.168.3.74',port=17851;
const server=http.createServer((req,res)=>{
const route=new URL(req.url,'http://localhost').pathname;
if(!['/','/index.html'].includes(route)){res.writeHead(404,{'Content-Type':'text/plain; charset=utf-8'});res.end('Not found');return;}
if(!['GET','HEAD'].includes(req.method)){res.writeHead(405);res.end();return;}
const html=fs.readFileSync(path.join(root,'index.html'));
res.writeHead(200,{'Content-Type':'text/html; charset=utf-8','Cache-Control':'no-store','Content-Length':html.length});
res.end(req.method==='HEAD'?undefined:html);
});
server.listen(port,host,()=>console.log(`NumberSwipe DEMO: http://${host}:${port}/`));
server.on('error',error=>{console.error(error.message);process.exitCode=1;});