2022-08-24 19:25:27 +02:00
|
|
|
#!/usr/bin/env node
|
2021-02-04 19:15:23 +01:00
|
|
|
const http = require('http');
|
|
|
|
const path = require('path');
|
2020-07-10 05:15:29 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const serveHandler = require('serve-handler');
|
2020-07-10 05:15:29 +02:00
|
|
|
|
|
|
|
const createStaticServer = (rootDirectory) => {
|
|
|
|
return http.createServer((request, response) => {
|
|
|
|
if (request.url.startsWith('/node_modules/')) {
|
2021-02-04 19:15:23 +01:00
|
|
|
request.url = request.url.substr(14);
|
2020-07-10 05:15:29 +02:00
|
|
|
return serveHandler(request, response, {
|
|
|
|
directoryListing: false,
|
|
|
|
public: path.resolve('./node_modules'),
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-07-10 05:15:29 +02:00
|
|
|
}
|
|
|
|
return serveHandler(request, response, {
|
|
|
|
directoryListing: false,
|
|
|
|
public: rootDirectory,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2020-07-10 05:15:29 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
module.exports = createStaticServer;
|