mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-02-03 23:09:17 -05:00
switch to express 5
It's needed for the better separation between rest api and web interface.
This commit is contained in:
parent
1fe0cedbd0
commit
8259455ac5
3 changed files with 24 additions and 16 deletions
|
@ -4,6 +4,7 @@ var fs = require('fs')
|
||||||
var marked = require('marked')
|
var marked = require('marked')
|
||||||
var Handlebars = require('handlebars')
|
var Handlebars = require('handlebars')
|
||||||
var Error = require('http-errors')
|
var Error = require('http-errors')
|
||||||
|
var bodyParser = require('body-parser')
|
||||||
var Search = require('./search')
|
var Search = require('./search')
|
||||||
var Middleware = require('./middleware')
|
var Middleware = require('./middleware')
|
||||||
|
|
||||||
|
@ -12,7 +13,7 @@ module.exports = function(config, auth, storage) {
|
||||||
var can = Middleware.allow(config)
|
var can = Middleware.allow(config)
|
||||||
|
|
||||||
app.use(Cookies.express())
|
app.use(Cookies.express())
|
||||||
app.use(express.urlencoded())
|
app.use(bodyParser.urlencoded({ extended: false }))
|
||||||
app.use(auth.cookie_middleware())
|
app.use(auth.cookie_middleware())
|
||||||
app.use(function(req, res, next) {
|
app.use(function(req, res, next) {
|
||||||
// disable loading in frames (clickjacking, etc.)
|
// disable loading in frames (clickjacking, etc.)
|
||||||
|
@ -47,7 +48,7 @@ module.exports = function(config, auth, storage) {
|
||||||
// Static
|
// Static
|
||||||
app.get('/-/static/:filename', function(req, res, next) {
|
app.get('/-/static/:filename', function(req, res, next) {
|
||||||
var file = __dirname + '/static/' + req.params.filename
|
var file = __dirname + '/static/' + req.params.filename
|
||||||
res.sendfile(file, function(err) {
|
res.sendFile(file, function(err) {
|
||||||
if (!err) return;
|
if (!err) return;
|
||||||
if (err.status === 404) {
|
if (err.status === 404) {
|
||||||
next()
|
next()
|
||||||
|
|
28
lib/index.js
28
lib/index.js
|
@ -2,6 +2,8 @@ var Cookies = require('cookies')
|
||||||
var express = require('express')
|
var express = require('express')
|
||||||
var fs = require('fs')
|
var fs = require('fs')
|
||||||
var Error = require('http-errors')
|
var Error = require('http-errors')
|
||||||
|
var expressJson5 = require('express-json5')
|
||||||
|
var compression = require('compression')
|
||||||
var Auth = require('./auth')
|
var Auth = require('./auth')
|
||||||
var Logger = require('./logger')
|
var Logger = require('./logger')
|
||||||
var Config = require('./config')
|
var Config = require('./config')
|
||||||
|
@ -66,8 +68,8 @@ module.exports = function(config_hash) {
|
||||||
})
|
})
|
||||||
app.use(Cats.middleware)
|
app.use(Cats.middleware)
|
||||||
app.use(auth.auth_middleware())
|
app.use(auth.auth_middleware())
|
||||||
app.use(express.json({ strict: false, limit: config.max_body_size || '10mb' }))
|
app.use(expressJson5({ strict: false, limit: config.max_body_size || '10mb' }))
|
||||||
app.use(express.compress())
|
app.use(compression())
|
||||||
app.use(Middleware.anti_loop(config))
|
app.use(Middleware.anti_loop(config))
|
||||||
|
|
||||||
// validate all of these params as a package name
|
// validate all of these params as a package name
|
||||||
|
@ -382,16 +384,6 @@ module.exports = function(config_hash) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
app.use(app.router)
|
|
||||||
app.use(function(err, req, res, next) {
|
|
||||||
if (typeof(res.report_error) !== 'function') {
|
|
||||||
// in case of very early error this middleware may not be loaded before error is generated
|
|
||||||
// fixing that
|
|
||||||
error_reporting_middleware(req, res, function(){})
|
|
||||||
}
|
|
||||||
res.report_error(err)
|
|
||||||
})
|
|
||||||
|
|
||||||
if (config.web && config.web.enable) {
|
if (config.web && config.web.enable) {
|
||||||
app.use(require('./index-web')(config, auth, storage))
|
app.use(require('./index-web')(config, auth, storage))
|
||||||
} else {
|
} else {
|
||||||
|
@ -400,10 +392,20 @@ module.exports = function(config_hash) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
app.use(function(req, res, next) {
|
app.get('/*', function(req, res, next) {
|
||||||
next( Error[404]('file not found') )
|
next( Error[404]('file not found') )
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.use(function(err, req, res, next) {
|
||||||
|
if (err.code === 'ECONNABORT' && res.statusCode === 304) return
|
||||||
|
if (typeof(res.report_error) !== 'function') {
|
||||||
|
// in case of very early error this middleware may not be loaded before error is generated
|
||||||
|
// fixing that
|
||||||
|
error_reporting_middleware(req, res, function(){})
|
||||||
|
}
|
||||||
|
res.report_error(err)
|
||||||
|
})
|
||||||
|
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,12 @@ bin:
|
||||||
sinopia: ./bin/sinopia
|
sinopia: ./bin/sinopia
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
express: '>=3.15.0 <4.0.0-0'
|
express: '>=5.0.0-0 <6.0.0-0'
|
||||||
|
|
||||||
|
# express middlewares
|
||||||
|
express-json5: '>=0.1.0 <1.0.0-0'
|
||||||
|
body-parser: '>=1.9.2 <2.0.0-0'
|
||||||
|
compression: '>=1.2.0 <2.0.0-0'
|
||||||
|
|
||||||
commander: '>=2.3.0 <3.0.0-0'
|
commander: '>=2.3.0 <3.0.0-0'
|
||||||
js-yaml: '>=3.0.1 <4.0.0-0'
|
js-yaml: '>=3.0.1 <4.0.0-0'
|
||||||
|
|
Loading…
Add table
Reference in a new issue