-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve.js
37 lines (33 loc) · 897 Bytes
/
serve.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/node
//
// This script will run a local development server. This is useful when
// developing the theme.
//
// Usage:
// `serve.js` to use the default JSONResume example
// `serve.js <filename>` to open a particular resume file
var http = require("http");
var fs = require('fs');
var args = require('optimist').argv;
var port = 8888;
http.createServer(async function (req, res) {
if (req.url === '/') {
res.writeHead(200, {
"Content-Type": "text/html"
});
res.end(await render());
}
}).listen(port);
console.log("Preview: http://localhost:8888/");
console.log("Serving..");
async function render() {
try {
var resume = args._.length
? JSON.parse(fs.readFileSync(args._[0], 'utf8'))
: require("resume-schema").resumeJson;
return await require("./index.js").render(resume);
} catch (e) {
console.log(e.message);
return "";
}
}