virtual-star/serve.js
2025-04-21 21:46:30 -04:00

26 lines
655 B
JavaScript

// based on the minimal demo from https://www.npmjs.com/package/serve
import handler from 'serve-handler';
import http from 'http';
import 'dotenv/config';
import { ENV } from './lib/env.js';
import { BasePaths } from './lib/render/base-paths.js';
const isDebugEnabled = ENV.getBoolean('VS_DEBUG');
const directory = BasePaths.targetRoot();
const options = {
public: directory,
directoryListing: isDebugEnabled,
};
const server = http.createServer((req, res) => {
return handler(req, res, options);
});
server.listen(3000, () => {
console.log('Running on port 3000');
if(isDebugEnabled) {
console.log(options);
}
});