jsWeb is a program to simplify web api based on express development. After installed jsweb, just write the express request handle js file and put them to the correctly directlry. Start with command:
> jsweb [/path/to/site/home]
> jsweb --site=/path/to/site/home --port=8888
- Everythings of web site in single folder.
- Multiple port support, each port is a standalone process
- Auto reload, Add/Modify/Delete api file doesn’t need restart server
- Async init script loaded before real api method load to prepare system like database object or connection
- Https support
- Virtual host support
- Mustache template support buildin
- Cluster support
- Parameter URL support
- TLS session resume support
$ sudo npm install jsweb -g
jsweb
is not a nodejs module but a system tools to run your web.
$ git clone https://github.com/jsplne/jsweb-demo
$ jsweb jsweb-demo/static
$ jsweb jsweb-demo/api-server
$ jsweb jsweb-demo/vhost
name[(tag[;tag[...]])]
https
This is a https port
## tags for root folder
api
Root folder.js
file treat as server side script, ifindex.js
exists, website homepage will be the result ofindex.js
## tags for inside folder
api
Folder contain api script. all.js
inside this folder will be called as api call, include subfolders.param
Folder correspond URL position will be inteperate as req.params object member, folder name as the member name, URL path will be the valuefinal
Match rest of url after final tag as req.params.final
## tags for api .js
file
- GET api will called for correspond http method, if omit, all method will called.
- POST
- PUT
- … all valid HTTP method
System information share with request callback via : req.jw
req.jw = {
app : <express object> // system object
}
Set/clear file execute flag of files to enable/disable init file or web api file to be load.
See [jsweb-demo](https://github.com/jsPLNE/jsweb-demo)
cd /path/to/https-port/config
$ openssl genrsa -out jsweb.key 1024
$ openssl req -new -key jsweb.key -out jsweb.ca
$ openssl x509 -req -in jsweb.ca -signkey jsweb.key -out jsweb.cert
Set port-config.json under the port folder with key/value: "cluster" : true
{
"bind" : "127.0.0.1",
"cluster" : true,
"tls" {
"key" : "/path/to/key/file", default to
"cert" : "/path/to/cert/file",
"ca" : "/path/to/ca/file",
"rejectUnauthorized" : true | false,
"requestCert" : true | false
}
}
- About parameter URL
api's
priority is higher than paramparam
folder - -index.js
underparam
folder will be called when url point to that folderparam
can set multiple level.param
folder examples/root/org(param)/user(param)/device(param)/index.js /root/org(param)/user(param)/device(param)/index.js
Put variables you want to reder within view to res.locals
and res.render(...)
req.jw
objectreq.jw.port.home
req.jw.port.port
req.jw.port.protocol
req.jw.port.tags
req.jw.port.config
req.jw.home
req.jw.root
req.jw.lib
req.jw.config
req.jw.hostname
debug
: true or faslecluster
: true or fasepublic
: array