Moved out code from download to serve method

This commit is contained in:
Nazar Gargol 2019-06-20 13:23:58 +02:00
parent c3b14f82fd
commit 8709f5cc55
2 changed files with 21 additions and 20 deletions

View File

@ -66,5 +66,24 @@ const activate = (filePath) => {
});
};
const serve = () => {
const routesPath = path.join(config.getContentPath('settings'), 'routes.yaml');
return fs.readFile(routesPath, 'utf-8')
.catch((err) => {
if (err.code === 'ENOENT') {
return Promise.resolve([]);
}
if (common.errors.utils.isIgnitionError(err)) {
throw err;
}
throw new common.errors.NotFoundError({
err: err
});
});
};
module.exports.activate = activate;
// module.exports.serve = serve;
module.exports.serve = serve;

View File

@ -1,8 +1,5 @@
const Promise = require('bluebird');
const _ = require('lodash');
const fs = require('fs-extra');
const path = require('path');
const config = require('../../config');
const models = require('../../models');
const frontendRouting = require('../../../frontend/services/routing');
const common = require('../../lib/common');
@ -168,22 +165,7 @@ module.exports = {
method: 'browse'
},
query() {
const routesPath = path.join(config.getContentPath('settings'), 'routes.yaml');
return fs.readFile(routesPath, 'utf-8')
.catch((err) => {
if (err.code === 'ENOENT') {
return Promise.resolve([]);
}
if (common.errors.utils.isIgnitionError(err)) {
throw err;
}
throw new common.errors.NotFoundError({
err: err
});
});
return frontendRouting.settings.serve();
}
}
};