mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Split createStaticServer
from static-server.js
(#8955)
The `createStaticServer` function was split from the `static-server.js` script, so that the static server could be constructed programmatically. `static-server.js` remains responsible for the CLI. This was done to make it easier to programmatically start the test dapp from e2e tests.
This commit is contained in:
parent
54365a2e2f
commit
46675f78ae
22
development/create-static-server.js
Normal file
22
development/create-static-server.js
Normal file
@ -0,0 +1,22 @@
|
||||
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
|
@ -1,10 +1,10 @@
|
||||
const fs = require('fs')
|
||||
const http = require('http')
|
||||
const path = require('path')
|
||||
|
||||
const chalk = require('chalk')
|
||||
const pify = require('pify')
|
||||
const serveHandler = require('serve-handler')
|
||||
|
||||
const createStaticServer = require('./create-static-server')
|
||||
|
||||
const fsStat = pify(fs.stat)
|
||||
const DEFAULT_PORT = 9080
|
||||
@ -24,19 +24,7 @@ const onRequest = (request, response) => {
|
||||
}
|
||||
|
||||
const startServer = ({ port, rootDirectory }) => {
|
||||
const server = 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,
|
||||
})
|
||||
})
|
||||
const server = createStaticServer(rootDirectory)
|
||||
|
||||
server.on('request', onRequest)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user