mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
test(cloudcmd) replacePrefix
This commit is contained in:
parent
cc30178aaa
commit
bdb7bee0b0
2 changed files with 16 additions and 1 deletions
|
|
@ -283,6 +283,11 @@ function logout(req, res, next) {
|
|||
res.sendStatus(401);
|
||||
}
|
||||
|
||||
module.exports._replacePrefix = replacePrefix;
|
||||
function replacePrefix(url, prefix) {
|
||||
return url.replace(prefix, '') || '/';
|
||||
}
|
||||
|
||||
function _setUrl(pref, req, res, next) {
|
||||
const prefix = getPrefix(pref);
|
||||
const is = !req.url.indexOf(prefix);
|
||||
|
|
@ -290,7 +295,7 @@ function _setUrl(pref, req, res, next) {
|
|||
if (!is)
|
||||
return next();
|
||||
|
||||
req.url = req.url.replace(prefix, '') || '/';
|
||||
req.url = replacePrefix(req.url, prefix);
|
||||
|
||||
if (/^\/cloudcmd\.js(\.map)?$/.test(req.url))
|
||||
req.url = `/dist${req.url}`;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ const {
|
|||
_authenticate,
|
||||
_getPrefix,
|
||||
_authCheck,
|
||||
_replacePrefix,
|
||||
} = cloudcmd;
|
||||
|
||||
test('cloudcmd: args: no', (t) => {
|
||||
|
|
@ -70,6 +71,15 @@ test('cloudcmd: getPrefix: function', (t) => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: replacePrefix', (t) => {
|
||||
const url = '/hello';
|
||||
const prefix = url;
|
||||
const result = _replacePrefix(url, prefix);
|
||||
|
||||
t.equal(result, '/', 'should equal');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: authCheck: success', (t) => {
|
||||
const auth = config('auth');
|
||||
const success = sinon.stub();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue