Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #381 fix #385

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/index-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var Handlebars = require('handlebars')
var renderReadme = require('render-readme')
var Search = require('./search')
var Middleware = require('./middleware')
var utils = require('./utils')
var match = Middleware.match
var validate_name = Middleware.validate_name
var validate_pkg = Middleware.validate_package
Expand Down Expand Up @@ -42,7 +43,7 @@ module.exports = function(config, auth, storage) {
}
app.get('/', function(req, res, next) {
var base = config.url_prefix
? config.url_prefix.replace(/\/$/, '')
? utils.buildUrlPrefix(config.url_prefix, req)
: req.protocol + '://' + req.get('host')
res.setHeader('Content-Type', 'text/html')

Expand Down Expand Up @@ -104,15 +105,15 @@ module.exports = function(config, auth, storage) {
}

var base = config.url_prefix
? config.url_prefix.replace(/\/$/, '')
? utils.buildUrlPrefix(config.url_prefix, req)
: req.protocol + '://' + req.get('host')
res.redirect(base)
})
})

app.post('/-/logout', function(req, res, next) {
var base = config.url_prefix
? config.url_prefix.replace(/\/$/, '')
? utils.buildUrlPrefix(config.url_prefix, req)
: req.protocol + '://' + req.get('host')
res.cookies.set('token', '')
res.redirect(base)
Expand Down
3 changes: 3 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ module.exports = function(config_hash) {
// it shouldn't make any difference anyway
app.set('env', process.env.NODE_ENV || 'production')

// use x-forwarded-for if present
app.enable('trust proxy');

function error_reporting_middleware(req, res, next) {
res.report_error = res.report_error || function(err) {
if (err.status && err.status >= 400 && err.status < 600) {
Expand Down
10 changes: 9 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports.filter_tarball_urls = function(pkg, req, config) {
var filename = URL.parse(_url).pathname.replace(/^.*\//, '')

if (config.url_prefix != null) {
var result = config.url_prefix.replace(/\/$/, '')
var result = buildUrlPrefix(config.url_prefix, req);
} else {
var result = req.protocol + '://' + req.headers.host
}
Expand All @@ -80,6 +80,14 @@ module.exports.filter_tarball_urls = function(pkg, req, config) {
return pkg
}

module.exports.buildUrlPrefix = buildUrlPrefix;

function buildUrlPrefix(url_prefix, req){
var result = url_prefix.replace(/\/$/, '');
result = result.replace(/\${scheme}/,req.protocol);
result = result.replace(/\${host}/,req.get('host'));
}

function can_add_tag(tag, config) {
if (!tag) return false
if (tag === 'latest' && config.ignore_latest_tag) return false
Expand Down