Simplify middleware
This commit is contained in:
parent
c3d9ede460
commit
db8f1fa5a0
@ -72,7 +72,7 @@ const createServer = (config) => {
|
|||||||
maxAge: '365d'
|
maxAge: '365d'
|
||||||
}))
|
}))
|
||||||
|
|
||||||
app.use(middleware.createRequestHandler(config))
|
app.use(middleware(config))
|
||||||
|
|
||||||
const server = http.createServer(app)
|
const server = http.createServer(app)
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ const defaultServerConfig = {
|
|||||||
port: parseInt(process.env.PORT, 10) || 5000,
|
port: parseInt(process.env.PORT, 10) || 5000,
|
||||||
publicDir: 'public',
|
publicDir: 'public',
|
||||||
|
|
||||||
// for express-unpkg
|
// for the middleware
|
||||||
registryURL: process.env.REGISTRY_URL || 'https://registry.npmjs.org',
|
registryURL: process.env.REGISTRY_URL || 'https://registry.npmjs.org',
|
||||||
redirectTTL: process.env.REDIRECT_TTL || 500,
|
redirectTTL: process.env.REDIRECT_TTL || 500,
|
||||||
autoIndex: !process.env.DISABLE_INDEX
|
autoIndex: !process.env.DISABLE_INDEX
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
const http = require('http')
|
|
||||||
const tmpdir = require('os-tmpdir')
|
const tmpdir = require('os-tmpdir')
|
||||||
const { join: joinPaths } = require('path')
|
const { join: joinPaths } = require('path')
|
||||||
const { stat: statFile, readFile } = require('fs')
|
const { stat: statFile, readFile } = require('fs')
|
||||||
@ -28,11 +27,11 @@ const checkLocalCache = (dir, callback) =>
|
|||||||
callback(stats && stats.isFile())
|
callback(stats && stats.isFile())
|
||||||
})
|
})
|
||||||
|
|
||||||
const ResolveExtensions = [ '', '.js', '.json' ]
|
|
||||||
|
|
||||||
const createTempPath = (name) =>
|
const createTempPath = (name) =>
|
||||||
joinPaths(tmpdir(), `unpkg-${name}`)
|
joinPaths(tmpdir(), `unpkg-${name}`)
|
||||||
|
|
||||||
|
const ResolveExtensions = [ '', '.js', '.json' ]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves a path like "lib/file" into "lib/file.js" or
|
* Resolves a path like "lib/file" into "lib/file.js" or
|
||||||
* "lib/file.json" depending on which one is available, similar
|
* "lib/file.json" depending on which one is available, similar
|
||||||
@ -264,15 +263,4 @@ const createRequestHandler = (options = {}) => {
|
|||||||
return handleRequest
|
return handleRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
module.exports = createRequestHandler
|
||||||
* Creates and returns an HTTP server that serves files from NPM packages.
|
|
||||||
*/
|
|
||||||
const createServer = (options) =>
|
|
||||||
http.createServer(
|
|
||||||
createRequestHandler(options)
|
|
||||||
)
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
createRequestHandler,
|
|
||||||
createServer
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user