2023-02-20 16:46:46 +00:00
|
|
|
module.exports = async (config) => {
|
2023-03-06 05:56:03 +00:00
|
|
|
let isReady = false;
|
|
|
|
const http = require("http"),
|
|
|
|
address = require("network-address"),
|
|
|
|
handler = require("serve-handler"),
|
|
|
|
build = require("./build"),
|
|
|
|
{
|
|
|
|
build: buildOpts,
|
|
|
|
logFunction: log = () => {},
|
|
|
|
serve: serveOpts,
|
|
|
|
} = config || {},
|
|
|
|
{ outputPath, srcPath } = buildOpts || {},
|
|
|
|
{ port = 5000 } = serveOpts || {},
|
|
|
|
server = http.createServer((request, response) => {
|
|
|
|
// You pass two more arguments for config and middleware
|
|
|
|
// More details here: https://github.com/vercel/serve-handler#options
|
|
|
|
return handler(request, response, { public: outputPath });
|
|
|
|
});
|
2023-02-20 16:46:46 +00:00
|
|
|
|
2023-03-06 05:56:03 +00:00
|
|
|
await build(config);
|
2023-02-20 16:46:46 +00:00
|
|
|
|
2023-03-06 05:56:03 +00:00
|
|
|
server.listen(port, async () => {
|
|
|
|
log(
|
|
|
|
`Running at http://${address()}:${port} / http://localhost:${port}`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|