Skip to content

Commit f82e27f

Browse files
committed
move code to lib/
1 parent d4f3d4d commit f82e27f

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ The `--https` or `--ssl` flags are intended for development and/or testing purpo
101101

102102
## Changelog
103103

104-
1.7.0 - add option to include own ssl certificate (thanks dpraul)
105-
1.6.0 - add --config option (thanks dpraul)
106-
1.5.0 - add --open option (thanks tluanga34)
107-
1.4.0 - add --path option (thanks nick-bogdanov)
104+
- 1.8.0 - rewrite of path resolution (thanks dpraul)
105+
- 1.7.0 - add option to include own ssl certificate (thanks dpraul)
106+
- 1.6.0 - add --config option (thanks dpraul)
107+
- 1.5.0 - add --open option (thanks tluanga34)
108+
- 1.4.0 - add --path option (thanks nick-bogdanov)
108109

109110
## Contributing
110111

angular-http-server.js renamed to lib/angular-http-server.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
#!/usr/bin/env node
22

33
var fs = require("fs");
4-
var argv = require("minimist")(process.argv.slice(2));
5-
var mime = require("mime");
64
var path = require("path");
5+
var mime = require("mime");
76
var pem = require("pem");
87
var https = require("https");
98
var http = require("http");
109
var opn = require("opn");
1110

12-
const getFilePathFromUrl = require('./lib/get-file-path-from-url');
13-
11+
var argv = require("minimist")(process.argv.slice(2));
12+
const getFilePathFromUrl = require('./get-file-path-from-url');
1413

1514
const NO_PATH_FILE_ERROR_MESSAGE =
1615
"Error: index.html could not be found in the specified path ";
17-
const NO_ROOT_FILE_ERROR_MESSAGE =
18-
"Error: Could not find index.html within the working directory.";
1916

17+
// if using config file, load that first
2018
if (argv.config) {
2119
let configPath;
2220
if (path.isAbsolute(argv.config)) {
@@ -32,11 +30,13 @@ if (argv.config) {
3230
config = getConfig;
3331
}
3432
// supplement argv with config, but CLI args take precedence
35-
argv = Object.assign({}, config, argv);
33+
argv = Object.assign(config, argv);
3634
}
3735

36+
// Pre-process arguments
3837
const useHttps = argv.ssl || argv.https;
3938
const basePath = argv.path ? path.resolve(argv.path) : process.cwd();
39+
const port = getPort(argv.p);
4040

4141
// As a part of the startup - check to make sure we can access index.html
4242
returnDistFile(true);
@@ -71,11 +71,11 @@ if (useHttps) {
7171
}
7272

7373
function start() {
74-
server.listen(getPort(), function() {
74+
server.listen(port, function() {
7575
if (argv.open == true || argv.o) {
76-
opn((useHttps ? "https" : "http") + "://localhost:" + getPort());
76+
opn((useHttps ? "https" : "http") + "://localhost:" + port);
7777
}
78-
return console.log("Listening on " + getPort());
78+
return console.log("Listening on " + port);
7979
});
8080
}
8181

@@ -119,9 +119,9 @@ function requestListener(req, res) {
119119
});
120120
}
121121

122-
function getPort() {
123-
if (argv.p) {
124-
var portNum = parseInt(argv.p);
122+
function getPort(portNo) {
123+
if (portNo) {
124+
var portNum = parseInt(portNo);
125125
if (!isNaN(portNum)) {
126126
return portNum;
127127
} else {

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
},
1919
"contributors": [
2020
{
21+
"name": "dpraul"
22+
},{
2123
"name": "Dale Myszewski",
2224
"email": "dale@daleslab.com"
2325
},
@@ -33,7 +35,7 @@
3335
},
3436
"preferGlobal": true,
3537
"bin": {
36-
"angular-http-server": "./angular-http-server.js"
38+
"angular-http-server": "./lib/angular-http-server.js"
3739
},
3840
"dependencies": {
3941
"mime": "^1.3.6",

0 commit comments

Comments
 (0)