-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more graceful error handling when reading file
- Loading branch information
Showing
1 changed file
with
28 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,37 @@ | ||
const getPort = require("get-port"); | ||
const argv = require("yargs").argv; | ||
const getPort = require('get-port'); | ||
const argv = require('yargs').argv; | ||
const fs = require('fs'); | ||
|
||
const AietesServer = require("../mock-server"); | ||
const AietesServer = require('../mock-server'); | ||
|
||
standalone = async () => { | ||
console.info("Starting Aietes standalone"); | ||
const standalone = async() => { | ||
console.info('Starting Aietes standalone'); | ||
|
||
const port = argv.port || await getPort(); | ||
const port = argv.port || await getPort(); | ||
|
||
const responseFileName = argv.json; | ||
let jsonResponse; | ||
if (responseFileName) { | ||
jsonResponse = JSON.parse(await fs.readFile(responseFileName, 'utf8')); | ||
const responseFileName = argv.json; | ||
let jsonResponse; | ||
if (responseFileName) { | ||
try { | ||
jsonResponse = JSON.parse(fs.readFileSync(responseFileName, 'utf8')); | ||
} catch (err) { | ||
console.error(err.message); | ||
console.error(`Reading response definition file '${responseFileName}' failed. Aietes exiting.`); | ||
process.exit(1); | ||
} | ||
} | ||
const response = jsonResponse || { | ||
'/': { | ||
get: { | ||
status: 200, | ||
headers: {}, | ||
data: { hello: 'Aietes' } | ||
} | ||
} | ||
}; | ||
|
||
const response = jsonResponse || { | ||
"/": { | ||
get: { | ||
status: 200, | ||
headers: {}, | ||
data: { hello: "Aietes"} | ||
} | ||
} | ||
}; | ||
const standaloneMock = new AietesServer(response, port); | ||
standaloneMock.start(); | ||
const standaloneMock = new AietesServer(response, port); | ||
standaloneMock.start(); | ||
}; | ||
|
||
module.exports = standalone(); | ||
module.exports = standalone(); |