mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-18 00:47:01 +00:00
feature(cloudcmd) prefix could be function
This commit is contained in:
parent
080a458712
commit
61c7afa635
2 changed files with 19 additions and 5 deletions
2
HELP.md
2
HELP.md
|
|
@ -274,7 +274,7 @@ server = http.createServer(app);
|
|||
socket = io.listen(server);
|
||||
|
||||
app.use(cloudcmd({
|
||||
prefix: '/prefix', /* base URL (optional) */
|
||||
prefix: '/prefix', /* base URL or function which returns base URL (optional) */
|
||||
socket: socket, /* used by Config, Edit (optional) and Console (required) */
|
||||
config: {} /* config data (optional) */
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -34,12 +34,23 @@
|
|||
|
||||
emptyFunc.middle = function() {
|
||||
return emptyFunc;
|
||||
},
|
||||
};
|
||||
|
||||
function getPrefix(prefix) {
|
||||
var result;
|
||||
|
||||
if (typeof prefix === 'function')
|
||||
result = prefix();
|
||||
else
|
||||
result = prefix;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = function(params) {
|
||||
var p = params || {},
|
||||
options = p.config || {},
|
||||
prefix = p.prefix || '',
|
||||
prefix = p.prefix,
|
||||
keys = Object.keys(options);
|
||||
|
||||
keys.forEach(function(name) {
|
||||
|
|
@ -168,9 +179,12 @@
|
|||
next();
|
||||
}
|
||||
|
||||
function setUrl(prefix) {
|
||||
function setUrl(pref) {
|
||||
return function(req, res, next) {
|
||||
var is = !req.url.indexOf(prefix);
|
||||
var is, prefix;
|
||||
|
||||
prefix = getPrefix(pref);
|
||||
is = !req.url.indexOf(prefix);
|
||||
|
||||
if (is) {
|
||||
req.url = req.url.replace(prefix, '') || '/';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue