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

View File

@ -9,8 +9,16 @@ users:
# crypto.createHash('sha1').update(pass).digest('hex')
password: __PASSWORD__
title: Sinopia
# logo: logo.png
web:
# 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:
htpasswd:

81
lib/index-web.js Normal file
View 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))
})
})
}

View File

@ -10,11 +10,7 @@ var express = require('express')
, validate_name = Middleware.validate_name
, media = Middleware.media
, expect_json = Middleware.expect_json
, Handlebars = require('handlebars')
, fs = require('fs')
, localList = require('./local-list')
, search = require('./search')
, marked = require('marked')
, Auth = require('./auth')
function match(regexp) {
@ -32,8 +28,6 @@ module.exports = function(config_hash) {
, storage = new Storage(config)
, auth = new Auth(config)
search.configureStorage(storage);
var can = function(action) {
return function(req, res, next) {
if (config['allow_'+action](req.params.package, req.remote_user)) {
@ -124,21 +118,6 @@ module.exports = function(config_hash) {
console.log(d)
})
})*/
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?
app.get('/:package/:version?', can('access'), function(req, res, next) {
@ -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
app.put('/:package/:tag', can('publish'), media('application/json'), function(req, res, next) {
if (typeof(req.body) !== 'string') return next('route')
@ -522,6 +442,16 @@ module.exports = function(config_hash) {
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
}