Skip to content

Commit 547cb5d

Browse files
author
Simon Hampton
committed
Merge branch 'feat/config-file' of https://github.com/fintechstudios/angular-http-server into fintechstudios-feat/config-file
2 parents 2a7e0e4 + 397db89 commit 547cb5d

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Single Page App dev-server
22

3-
A simple dev-server designed for Single Page App (SPA) developers. **`angular-http-server` is not, and makes no claims to be, a production server.**
3+
A simple dev-server designed for Single Page App (SPA) developers. **`angular-http-server` is not, and makes no claims to be, a production server.**
44

55
It returns a file if it exists (ex. your-icon.png, index.html), routes all other requests to index.html (rather than giving a 404 error) so that you SPO's routing can take over. The only time it will error out is if it can't locate the index.html file.
66

@@ -52,8 +52,41 @@ Disable logging
5252
angular-http-server --silent
5353
```
5454

55+
All options can be specified by a config file, optionally read via `--config` flag.
56+
CLI options take precedence over any options read from the config file.
57+
```sh
58+
angular-http-server --config configs/angular-http-server.config.js
59+
```
60+
5561
Feedback via: https://github.com/simonh1000/angular-http-server
5662

63+
## Config File
64+
The config file can either export an object of parameters, or a function that will be passed in the parsed `argv` from minimalist.
65+
66+
Simple example:
67+
```js
68+
module.exports = {
69+
p: 8081,
70+
cors: true,
71+
silent: true,
72+
};
73+
```
74+
75+
Complicated example:
76+
```js
77+
module.exports = (argv) => {
78+
const config = {
79+
cors: true,
80+
};
81+
82+
if (argv.p === 443) {
83+
config.ssl = true;
84+
}
85+
86+
return config;
87+
};
88+
```
89+
5790
## Self-Signed HTTPS Use
5891

5992
#### Production

angular-http-server.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,26 @@ var server;
1616
const NO_PATH_FILE_ERROR_MESSAGE = "Error: index.html could not be found in the specified path ";
1717
const NO_ROOT_FILE_ERROR_MESSAGE = "Error: Could not find index.html within the working directory.";
1818

19+
20+
if (argv.config) {
21+
let configPath;
22+
if (path.isAbsolute(argv.config)) {
23+
configPath = argv.config;
24+
} else {
25+
configPath = path.join(process.cwd(), argv.config);
26+
}
27+
const getConfig = require(configPath);
28+
let config;
29+
if (typeof getConfig === 'function') {
30+
config = getConfig(argv);
31+
} else {
32+
config = getConfig;
33+
}
34+
35+
// supplement argv with config, but CLI args take precedence
36+
argv = Object.assign({}, config, argv);
37+
}
38+
1939
// As a part of the startup - check to make sure we can access index.html
2040
returnDistFile(true);
2141

0 commit comments

Comments
 (0)