1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-08 23:25:51 +01:00

temporarily disable web interface in config

I want to release 0.10 soon, and web doesn't have auth system yet.

So we'll probably disable it for now, and re-enable when its ready.
This commit is contained in:
Alex Kocharin 2014-09-06 23:53:28 +04:00
parent 435ff1beeb
commit 504430dcdd
3 changed files with 101 additions and 82 deletions

@ -9,8 +9,16 @@ users:
# crypto.createHash('sha1').update(pass).digest('hex') # crypto.createHash('sha1').update(pass).digest('hex')
password: __PASSWORD__ password: __PASSWORD__
title: Sinopia web:
# logo: logo.png # web interface is disabled by default in 0.x, will be enabled soon in 1.x
# when all its issues will be fixed
#
# set this to `true` if you want to experiment with web ui now;
# this has a lot of issues, e.g. no auth yet, so use at your own risk
#enable: true
title: Sinopia
# logo: logo.png
auth: auth:
htpasswd: htpasswd:

81
lib/index-web.js Normal file

@ -0,0 +1,81 @@
var fs = require('fs')
var marked = require('marked')
var search = require('./search')
var Handlebars = require('handlebars')
var localList = require('./local-list')
module.exports = function(app, config, storage) {
search.configureStorage(storage)
Handlebars.registerPartial('entry', fs.readFileSync(require.resolve('./GUI/entry.hbs'), 'utf8'));
var template = Handlebars.compile(fs.readFileSync(require.resolve('./GUI/index.hbs'), 'utf8'));
app.get('/', function(req, res, next) {
res.setHeader('Content-Type', 'text/html');
storage.get_local(function(err, packages) {
res.send(template({
name: config.web.title || "Sinopia",
packages: packages,
baseUrl: config.url_prefix || req.protocol + '://' + req.get('host') + '/'
}));
});
});
// Static
app.get('/-/static/:filename', function(req, res, next) {
var file = __dirname + '/static/' + req.params.filename
fs.exists(file, function(exists) {
if (exists) {
res.sendfile(file)
} else {
res.status(404);
res.send("File Not Found")
}
})
})
app.get('/-/logo', function(req, res, next) {
res.sendfile(config.logo ? config.logo : __dirname + "/static/logo.png")
})
// Search
app.get('/-/search/:anything', function(req, res, next) {
var results = search.query(req.params.anything),
packages = []
var getData = function(i) {
storage.get_package(results[i].ref, function(err, entry) {
if (entry) {
packages.push(entry.versions[entry['dist-tags'].latest])
}
if (i >= results.length - 1) {
res.send(packages)
} else {
getData(i + 1)
}
})
}
if (results.length) {
getData(0);
} else {
res.send([])
}
})
// Readme
marked.setOptions({
highlight: function (code) {
return require('highlight.js').highlightAuto(code).value
}
})
app.get('/-/readme/:package/:version', function(req, res, next) {
storage.get_readme(req.params.package, req.params.version, function(readme) {
res.send(marked(readme))
})
})
}

@ -10,11 +10,7 @@ var express = require('express')
, validate_name = Middleware.validate_name , validate_name = Middleware.validate_name
, media = Middleware.media , media = Middleware.media
, expect_json = Middleware.expect_json , expect_json = Middleware.expect_json
, Handlebars = require('handlebars')
, fs = require('fs') , fs = require('fs')
, localList = require('./local-list')
, search = require('./search')
, marked = require('marked')
, Auth = require('./auth') , Auth = require('./auth')
function match(regexp) { function match(regexp) {
@ -32,8 +28,6 @@ module.exports = function(config_hash) {
, storage = new Storage(config) , storage = new Storage(config)
, auth = new Auth(config) , auth = new Auth(config)
search.configureStorage(storage);
var can = function(action) { var can = function(action) {
return function(req, res, next) { return function(req, res, next) {
if (config['allow_'+action](req.params.package, req.remote_user)) { if (config['allow_'+action](req.params.package, req.remote_user)) {
@ -125,21 +119,6 @@ module.exports = function(config_hash) {
}) })
})*/ })*/
Handlebars.registerPartial('entry', fs.readFileSync(require.resolve('./GUI/entry.hbs'), 'utf8'));
var template = Handlebars.compile(fs.readFileSync(require.resolve('./GUI/index.hbs'), 'utf8'));
app.get('/', can('access'), function(req, res, next) {
res.setHeader('Content-Type', 'text/html');
storage.get_local(function(err, packages) {
res.send(template({
name: config.title || "Sinopia",
packages: packages,
baseUrl: config.url_prefix || req.protocol + '://' + req.get('host') + '/'
}));
});
});
// TODO: anonymous user? // TODO: anonymous user?
app.get('/:package/:version?', can('access'), function(req, res, next) { app.get('/:package/:version?', can('access'), function(req, res, next) {
storage.get_package(req.params.package, {req: req}, function(err, info) { storage.get_package(req.params.package, {req: req}, function(err, info) {
@ -252,65 +231,6 @@ module.exports = function(config_hash) {
} }
}) })
// Static
app.get('/-/static/:filename', function(req, res, next) {
var file = __dirname + '/static/' + req.params.filename
fs.exists(file, function(exists) {
if(exists) {
res.sendfile(file);
}
else {
res.status(404);
res.send("File Not Found");
}
});
});
app.get('/-/logo', function(req, res, next) {
res.sendfile(config.logo ? config.logo : __dirname + "/static/logo.png");
});
// Search
app.get('/-/search/:anything', function(req, res, next) {
var results = search.query(req.params.anything),
packages = [];
var getData = function(i) {
storage.get_package(results[i].ref, function(err, entry) {
if(entry) {
packages.push(entry.versions[entry['dist-tags'].latest]);
}
if(i >= results.length - 1) {
res.send(packages);
}
else {
getData(i + 1);
}
});
};
if(results.length) {
getData(0);
}
else {
res.send([]);
}
});
// Readme
marked.setOptions({
highlight: function (code) {
return require('highlight.js').highlightAuto(code).value;
}
});
app.get('/-/readme/:package/:version', function(req, res, next) {
storage.get_readme(req.params.package, req.params.version, function(readme) {
res.send(marked(readme));
});
});
// tagging a package // tagging a package
app.put('/:package/:tag', can('publish'), media('application/json'), function(req, res, next) { app.put('/:package/:tag', can('publish'), media('application/json'), function(req, res, next) {
if (typeof(req.body) !== 'string') return next('route') if (typeof(req.body) !== 'string') return next('route')
@ -522,6 +442,16 @@ module.exports = function(config_hash) {
res.report_error(err) res.report_error(err)
}) })
if (config.web && config.web.enable) {
require('./index-web')(app, config, storage)
} else {
app.get('/', function(req, res) {
res.send('Web interface is a work-in-progress right now, '
+ 'so it is disabled by default. If you want to play with it, '
+ 'you can enable it in the config file.')
})
}
return app return app
} }