Skip to content

Commit

Permalink
fix(http): define baseurl at top of file
Browse files Browse the repository at this point in the history
  • Loading branch information
marisademeglio committed Jan 26, 2018
1 parent 08f4a46 commit 8161f39
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/ace-http/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const JOBSTATUS = {"done": 0, "processing": 1, "error": -1}
var server = express();
var upload = multer({dest: UPLOADS});
var joblist = [];
var baseurl = "";

const cli = meow(`
Usage: ace-http [options]
Expand Down Expand Up @@ -57,11 +58,11 @@ function run() {

var host = cli.flags.host ? cli.flags.host : DEFAULTHOST;
var port = cli.flags.port ? cli.flags.port : DEFAULTPORT;
var baseurl = "http://" + host + ":" + port; // just for convenience
baseurl = "http://" + host + ":" + port; // just for convenience

// todo customize port and hostname
server.listen(port, host, function() {
winston.info("Ace server listening on " + baseurl);
winston.info("[ace-http] server listening on " + baseurl);
});
}

Expand Down Expand Up @@ -144,22 +145,22 @@ function getReport(req, res) {

// start a new job
function newJob(jobdata) {
winston.info("Job started");
winston.info("[ace-http] Job started");
joblist.push(jobdata);

// execute the job with Ace
ace(jobdata.internal.epubPath, {'jobid': jobdata.internal.id, 'outdir': jobdata.internal.outputDir})
.then((jobData) => {
var jobId = jobData[0];
var idx = joblist.findIndex(job => job.internal.id === jobid);
winston.info("Job finished " + joblist[idx].internal.id);
winston.info("[ace-http] Job finished " + joblist[idx].internal.id);
joblist[idx].public.status = JOBSTATUS.done;
joblist[idx].public.report.zip = joblist[idx].public.job + "/report/?type=zip";
joblist[idx].public.report.json = joblist[idx].public.job + "/report/?type=json";
})
.catch((jobid) => {
var idx = joblist.findIndex(job => job.internal.id === jobid);
winston.info("Job error " + joblist[idx].internal.id);
winston.info("[ace-http] Job error " + joblist[idx].internal.id);
joblist[idx].public.status = JOBSTATUS.error;
});
}
Expand Down

0 comments on commit 8161f39

Please sign in to comment.