From df60dd7ba081e7bc62272810b043fb018a18f950 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 16 Mar 2021 17:44:54 +0200 Subject: [PATCH] fix(route) unable to navigate between folders (#333) --- server/route.js | 5 ++++- server/route.spec.js | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/server/route.js b/server/route.js index 787bab4a..c35c1716 100644 --- a/server/route.js +++ b/server/route.js @@ -79,7 +79,10 @@ async function route({config, options, request, response}) { const fullPath = root(rootName, config('root')); const read = getReadDir(config); - const [error, stream] = await tryToCatch(read, fullPath); + const [error, stream] = await tryToCatch(read, fullPath, { + root: config('root'), + }); + const {html} = options; if (error) diff --git a/server/route.spec.js b/server/route.spec.js index 10f67b7e..ed677e3f 100644 --- a/server/route.spec.js +++ b/server/route.spec.js @@ -28,7 +28,6 @@ const {request} = serveOnce(cloudcmd, { }); const {stringify} = JSON; - const {assign} = Object; test('cloudcmd: route: buttons: no console', async (t) => { @@ -459,3 +458,35 @@ test('cloudcmd: route: content length', async (t) => { t.end(); }); +test('cloudcmd: route: read: root', async (t) => { + const read = stub(); + + mockRequire('win32', { + read, + }); + + reRequire(routePath); + + const cloudcmd = reRequire(cloudcmdPath); + const configManager = createConfigManager(); + const root = '/hello'; + configManager('root', root); + + const {request} = serveOnce(cloudcmd, { + configManager, + }); + + await request.get('/fs/route.js'); + + stopAll(); + + const expected = [ + '/hello/route.js', { + root, + }, + ]; + + t.calledWith(read, expected); + t.end(); +}); +