Skip to content

Commit 431d114

Browse files
committed
2 parents 55ba389 + 5e31e68 commit 431d114

File tree

1 file changed

+118
-2
lines changed

1 file changed

+118
-2
lines changed

README.md

Lines changed: 118 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,118 @@
1-
# node-spserver
2-
Node static page server for running quick MVVM file server
1+
spserver
2+
=======
3+
4+
spserver (or single page server) is a simple helper utlity for creating/running a server for using in pure single-page applications in true MVVM fashion without having to write any node code or using nginx or anything. This can be helpful to jump start making any single-page applications and get it running in seconds.
5+
6+
How it works
7+
------------
8+
9+
spserver has two modes of serving files (minimum either has to be specified):
10+
11+
* Single file
12+
* Static folder
13+
14+
When specifying a single file, all url requests will resolve with the contents of said file. This is handy for MVVM applications where the front-end javascript handles all url path routing.
15+
16+
When specifying a static folder, it will first look up the url request on the static folder to see if the file exists. If it doesn't, it falls back to the single file (above) or 404 (if single file was not specified).
17+
18+
A combination of these two will allow you to create a single base.html that will bootstrap your MVVM application with the static folder containing the javascript files. For an example, see the [nfp_www](https://github.com/nfp-projects/nfp_www) project.
19+
20+
API
21+
===
22+
23+
`spserver(settings)`
24+
25+
* Settings for the server (see config below)
26+
27+
CLI
28+
===
29+
30+
How to use
31+
----------
32+
33+
```bash
34+
npm install -g spserver
35+
spserver -f ./myfile.html -s ./public -p 3000
36+
```
37+
38+
Options
39+
-------
40+
41+
`spserver --help`
42+
43+
By default, spserver will use the settings located in `config.json`. You can also override them or run it directly using only the commands below.
44+
45+
`--config, -c` Location of the config file for the server [default: config.json]
46+
47+
`--port, -p` The port server should bind to [default: 3001 or 80 in production mode]
48+
49+
`--file, -f` Single static file the server should serve on all unknown requests
50+
51+
`--bunyan, -b` Use bunyan instead of console to log to [default: true in production mode]
52+
53+
`--template, -t` Parse the static file as lodash template with all options/settings being passed to it
54+
55+
`--name, -n` The name for this server for logging [default: spserver]
56+
57+
`--serve, -s` Folder path to serve static files from [default: public]
58+
59+
`--prod, -P` Force run the server in production mode
60+
61+
`--debug, -d` Force run the server in development mode
62+
63+
Config
64+
======
65+
66+
The config file (default `config.json`) provides means to configure spserver in greater detail as well as provide optional settings to pass into our template (see template below).
67+
68+
A sample `config.json` file:
69+
```
70+
{
71+
"production": {
72+
"port": 80,
73+
"bunyan: {
74+
"name": "myserver",
75+
"use_bunyan": true,
76+
"streams": [{
77+
"file": "/var/log/server.log",
78+
"level": "info"
79+
}]
80+
}
81+
},
82+
"development": {
83+
"port": 5000,
84+
"use_bunyan": false
85+
}
86+
}
87+
```
88+
89+
Any of the settings in the `config.json` file can be overridden using the CLI options above.
90+
91+
Template
92+
========
93+
94+
spserver can also help provide any additional info to your single file thanks to lodash.template. If template mode is specified, it will parse the single file first through lodash.template with the whole config file. This can allow you to specify configuration in your config file and expose them in your single file.
95+
96+
Example:
97+
98+
`config.json`
99+
```
100+
{
101+
"api": "http://api.mysite.com"
102+
}
103+
```
104+
105+
`base.html`
106+
```
107+
<!doctype html>
108+
<body>
109+
<script>
110+
var apiUrl = "<%- api %>"
111+
</script>
112+
<script src="/js/lib/mithril.js"></script>
113+
<script src="/js/main.js"></script>
114+
</body
115+
```
116+
117+
Then you can run it like this:
118+
`spserver -c ./config.json -t -f ./base.html -s ./public`

0 commit comments

Comments
 (0)