diff --git a/server/route.js b/server/route.js index cfba8ad5..c368725a 100644 --- a/server/route.js +++ b/server/route.js @@ -26,7 +26,6 @@ const isDev = process.env.NODE_ENV === 'development'; const getIndexPath = () => { const dist = isDev ? 'dist-dev' : 'dist'; - return DIR + `${dist}/index.html`; }; @@ -214,17 +213,17 @@ function route(request, response, callback) { function buildIndex(json, callback) { fs.readFile(getIndexPath(), 'utf8', (error, template) => { if (error) - return; + return callback(error); const panel = CloudFunc.buildFromJSON({ - data: json,, + data: json, prefix: prefix(), - template: Template + template: Template, }); const data = indexProcessing({ panel, - data: template + data: template, }); callback(error, data); diff --git a/test/server/route.js b/test/server/route.js index 72fbb16a..0e54be5b 100644 --- a/test/server/route.js +++ b/test/server/route.js @@ -1,5 +1,6 @@ 'use strict'; +const path = require('path'); const test = require('tape'); const promisify = require('es6-promisify'); const pullout = require('pullout'); @@ -101,3 +102,24 @@ test('cloudcmd: route: buttons: no contact', (t) => { }); }); +test('cloudcmd: route: no index', (t) => { + const name = path.join(__dirname, '../../dist-dev/index.html'); + const nameAfter = path.join(__dirname, '../../dist-dev/index1.html'); + + const fs = require('fs'); + + fs.renameSync(name, nameAfter); + + const before = require('../before'); + + before({}, (port, after) => { + getStr(`http://localhost:${port}/`) + .then((result) => { + fs.renameSync(nameAfter, name); + t.equal(result.indexOf('ENOENT'), 0, 'should not found index.html'); + t.end(); + after(); + }); + }); +}); +