- Removed .save file
- Moved allowed api hosts into configuration file
- Determine first run by failed asset validation
This commit is contained in:
Felix 2016-09-12 17:08:57 +02:00
parent 6a983bc8be
commit 0eb318debc
4 changed files with 15 additions and 19 deletions

1
.save
View File

@ -1 +0,0 @@
{"isFirstRun":true,"allowedApiHosts":["localhost"],"loginDetails":{"username":"root","password":"1337"}}

View File

@ -13,6 +13,7 @@ export default {
API_ENABLE: true,
API_USERNAME: "root",
API_PASSWORD: "",
API_ALLOWED_HOSTS: ["localhost", "127.0.0.1"],
// Server settings
MAX_CONNECTIONS: 64,

View File

@ -17,15 +17,14 @@ let showHint = true;
export function processApiCall(req, res, route) {
let save = JSON.parse(fs.readFileSync(".save", "utf8"));
let allowedHosts = save.allowedApiHosts;
let allowedHosts = CFG.API_ALLOWED_HOSTS;
let hoster = url.parse(req.headers.referer).host;
if (!(allowedHosts.indexOf(hoster) > -1)) {
print(`Denied API access for ${hoster}!`, 31);
if (showHint) {
print(`To grant ${hoster} API access, add it to the allowed hosts in .save`, 33);
print(`To grant ${hoster} API access, add it to the allowed hosts in cfg.js`, 33);
showHint = false;
}
let result = {

View File

@ -20,20 +20,6 @@ export function setup() {
return new Promise((resolve, reject) => {
let save = JSON.parse(fs.readFileSync(".save", "utf8"));
if (save.isFirstRun) {
print("Required assets are missing! Preparing dump session..", 33);
setTimeout(() => {
this.onFirstRun(() => {
save.isFirstRun = false;
fs.writeFileSync(".save", JSON.stringify(save), "utf8");
this.setup().then(resolve);
});
}, 1e3);
return void 0;
}
// make sure all assets got loaded properly
this.validateAssets().then(() => {
@ -54,14 +40,25 @@ export function setup() {
});
}).catch((e) => {
//fse.removeSync(CFG.DUMP_ASSET_PATH);
print("Error: " + e + " was not found!", 31);
this.initDumpSession().then(resolve);
});
});
}
export function initDumpSession() {
print("Required assets are missing! Preparing dump session..", 33);
return new Promise((resolve, reject) => {
setTimeout(() => {
this.onFirstRun(() => {
this.setup().then(resolve);
});
}, 1e3);
});
}
/**
* Make sure all required
* assets got loaded properly