You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
600 B
23 lines
600 B
4 years ago
|
const http = require('http')
|
||
|
const path = require('path')
|
||
|
|
||
|
const serveHandler = require('serve-handler')
|
||
|
|
||
|
const createStaticServer = (rootDirectory) => {
|
||
|
return http.createServer((request, response) => {
|
||
|
if (request.url.startsWith('/node_modules/')) {
|
||
|
request.url = request.url.substr(14)
|
||
|
return serveHandler(request, response, {
|
||
|
directoryListing: false,
|
||
|
public: path.resolve('./node_modules'),
|
||
|
})
|
||
|
}
|
||
|
return serveHandler(request, response, {
|
||
|
directoryListing: false,
|
||
|
public: rootDirectory,
|
||
|
})
|
||
|
})
|
||
|
}
|
||
|
|
||
|
module.exports = createStaticServer
|