forked from jamesshore/lets_code_javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_run_server.js
More file actions
37 lines (30 loc) · 1.04 KB
/
_run_server.js
File metadata and controls
37 lines (30 loc) · 1.04 KB
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
// Copyright (c) 2013 Titanium I.T. LLC. All rights reserved. See LICENSE.TXT for details.
(function() {
"use strict";
var child_process = require("child_process");
var fs = require("fs");
var procfile = require("procfile");
exports.runInteractively = function() {
return run("inherit");
};
exports.runProgrammatically = function(callback) {
var serverProcess = run(["pipe", "pipe", process.stderr]);
serverProcess.stdout.setEncoding("utf8");
serverProcess.stdout.on("data", function(chunk) {
if (chunk.trim().indexOf("Server started") !== -1) callback(serverProcess);
});
};
function run(stdioOptions) {
var commandLine = parseProcFile();
return child_process.spawn(commandLine.command, commandLine.options, {stdio: stdioOptions });
}
function parseProcFile() {
var fileData = fs.readFileSync("Procfile", "utf8");
var webCommand = procfile.parse(fileData).web;
webCommand.options = webCommand.options.map(function(element) {
if (element === "$PORT") return "5000";
else return element;
});
return webCommand;
}
}());