fix(cloudcmd) prefix with leading slash (#195)

This commit is contained in:
coderaiser 2018-09-28 18:06:06 +03:00
parent 15abceefeb
commit b5f9261504
4 changed files with 7 additions and 10 deletions

View file

@ -11,6 +11,7 @@ const wraptile = require('wraptile');
const exit = require(DIR_SERVER + 'exit');
const config = require(DIR_SERVER + 'config');
const env = require(DIR_SERVER + 'env');
const prefixer = require(DIR_SERVER + '/prefixer');
const noop = () => {};
@ -150,7 +151,7 @@ function main() {
config('terminalCommand', args['terminal-command']);
config('terminalAutoRestart', args['terminal-auto-restart']);
config('editor', args.editor);
config('prefix', args.prefix);
config('prefix', prefixer(args.prefix));
config('root', args.root);
config('vim', args.vim);
config('columns', args.columns);

View file

@ -6,7 +6,7 @@ module.exports.unregisterSW = unregisterSW;
const noop = () => {};
async function registerSW(prefix) {
prefix = prefix ? `/${prefix}/` : `/`;
prefix = prefix ? `${prefix}/` : `/`;
if (!navigator.serviceWorker)
return;

View file

@ -104,7 +104,7 @@ test('sw: register: registerSW', async (t) => {
global.location = location;
global.navigator = navigator;
t.ok(register.calledWith('/hello/sw.js'), 'should call register');
t.ok(register.calledWith('hello/sw.js'), 'should call register');
t.end();
});

View file

@ -5,21 +5,17 @@ const cloudcmd = require(DIR_SERVER + 'cloudcmd');
const exit = require(DIR_SERVER + 'exit');
const config = require(DIR_SERVER + 'config');
const prefixer = require(DIR_SERVER + 'prefixer');
const http = require('http');
const opn = require('opn');
const express = require('express');
const io = require('socket.io');
const squad = require('squad');
const apart = require('apart');
const tryRequire = require('tryrequire');
const logger = tryRequire('morgan');
const prefix = squad(prefixer, apart(config, 'prefix'));
module.exports = (options) => {
const prefix = config('prefix');
const port = process.env.PORT || /* c9 */
config('port');
@ -36,7 +32,7 @@ module.exports = (options) => {
app.use(cloudcmd({
config: options,
socket: io(server, {
path: prefix() + '/socket.io'
path: `${prefix}/socket.io`,
}),
}));
@ -46,7 +42,7 @@ module.exports = (options) => {
server.listen(port, ip, () => {
const host = config('ip') || 'localhost';
const port0 = port || server.address().port;
const url = `http://${host}:${port0}${prefix()}/`;
const url = `http://${host}:${port0}${prefix}/`;
console.log('url:', url);