1 | # WebAppEngine [![build status](https://travis-ci.org/cheton/webappengine.svg?branch=master)](https://travis-ci.org/cheton/webappengine) [![Coverage Status](https://coveralls.io/repos/cheton/webappengine/badge.svg?branch=master&service=github)](https://coveralls.io/github/cheton/webappengine?branch=master)
|
2 |
|
3 | [![NPM](https://nodei.co/npm/webappengine.png?downloads=true&stars=true)](https://nodei.co/npm/webappengine/)
|
4 |
|
5 | A web application platform that can host multiple web apps running with Node.js.
|
6 |
|
7 | ![WebAppEngine](https://raw.githubusercontent.com/cheton/webappengine/master/media/screenshot.png)
|
8 | <i>Note. The administration UI is currently under construction.</i>
|
9 |
|
10 | ## Installation
|
11 | For the API usage:
|
12 | ```bash
|
13 | $ npm install --save webappengine
|
14 | ```
|
15 |
|
16 | For the command line usage:
|
17 | ```bash
|
18 | $ npm install -g webappengine
|
19 | ```
|
20 |
|
21 | ### Kickstart your project using [generator-webappengine](https://github.com/cheton/generator-webappengine)
|
22 | A Yeoman generator for developing WebAppEngine app is available at [https://github.com/cheton/generator-webappengine](https://github.com/cheton/generator-webappengine). You can use the generator to kickstart your project. It includes Gulp, Browserify, Babelify, Stylus, Handlebars, i18next, and React.
|
23 |
|
24 | Follow the steps to run the generator:
|
25 | ```bash
|
26 | $ npm install -g yo
|
27 | $ npm install -g generator-webappengine
|
28 | $ yo webappengine
|
29 | ```
|
30 |
|
31 | Once completed, you have to install NPM packages and Bower components, and run the `gulp` command to build your project.
|
32 | ```bash
|
33 | $ npm install
|
34 | $ bower install
|
35 | $ gulp
|
36 | ```
|
37 |
|
38 | Now you can run `node app/main.js` to launch your web app, or use webappengine to load [app.js](https://github.com/cheton/generator-webappengine/blob/master/generators/app/templates/app/app.js). For example:
|
39 | ```js
|
40 | var path = require('path');
|
41 | var webappengine = require('webappengine');
|
42 |
|
43 | webappengine({
|
44 | port: 80,
|
45 | routes: [
|
46 | {
|
47 | type: 'server',
|
48 | route: '/',
|
49 | server: function(options) {
|
50 | options = options || {};
|
51 |
|
52 | var app = express();
|
53 | var serveStatic = require('serve-static');
|
54 | var assetPath = path.resolve(__dirname, 'web');
|
55 |
|
56 | app.use(options.route, serveStatic(assetPath));
|
57 |
|
58 | return app;
|
59 | }
|
60 | }
|
61 | ]
|
62 | });
|
63 | ```
|
64 |
|
65 | ## Usage
|
66 |
|
67 | ### API usage
|
68 | ```js
|
69 | var path = require('path');
|
70 | var webappengine = require('webappengine');
|
71 | var options = {
|
72 | port: 80, // [optional] The listen port (default: 8000)
|
73 | //host: '', // [optional] The listen address or hostname (default: 0.0.0.0)
|
74 | //backlog: 511, // [optional] The listen backlog (default: 511)
|
75 | routes: [
|
76 | {
|
77 | type: 'static', // [static|server]
|
78 | route: '/',
|
79 | directory: path.resolve(__dirname, 'web') // for the static type
|
80 | }
|
81 | ]
|
82 | };
|
83 |
|
84 | webappengine(options)
|
85 | .on('ready', function(server) {
|
86 | var address = server.address();
|
87 | console.log('Server is listening on %s:%d', address.address, address.port);
|
88 |
|
89 | var io = require('socket.io')(server); // using socket.io
|
90 | });
|
91 | ```
|
92 |
|
93 | ### Command line usage
|
94 | Run `webappengine` to start the app, and visit `http://yourhostname:8000/` to check if it works:
|
95 |
|
96 | ```bash
|
97 | $ webappengine
|
98 | ```
|
99 |
|
100 | To check what port the app is running on, find the message `Server is listening on 0.0.0.0:8000` from console output.
|
101 |
|
102 | By default the app listens on port 8000, you can run `webappengine` with `-p` (or `--port`) to determine which port your application should listen on. For example:
|
103 | ```bash
|
104 | $ webappengine -p 80
|
105 | ```
|
106 |
|
107 | Set the environment variable `NODE_ENV` to `production` if you are running in production mode:
|
108 | ```bash
|
109 | $ NODE_ENV=production webappengine
|
110 | ```
|
111 |
|
112 | Run `webappengine` with `-h` for detailed usage:
|
113 | ```
|
114 | $ webappengine -h
|
115 |
|
116 | Usage: webappengine [options]
|
117 |
|
118 | Options:
|
119 |
|
120 | -h, --help output usage information
|
121 | -V, --version output the version number
|
122 | -p, --port set listen port (default: 8000)
|
123 | -H, --host <host> set listen address or hostname (default: 0.0.0.0)
|
124 | -b, --backlog set listen backlog (default: 511)
|
125 | -c, --config <filename> set multihost configuration file
|
126 | -v, --verbose increase the verbosity level
|
127 | ```
|
128 |
|
129 | ## Getting Started
|
130 |
|
131 | ### Working with static assets
|
132 | The following configuration will serve static assets from the directory:
|
133 |
|
134 | static-config.json:
|
135 | ```json
|
136 | [
|
137 | {
|
138 | "type": "static",
|
139 | "route": "/",
|
140 | "directory": "/path/to/your/project/web/"
|
141 | }
|
142 | ]
|
143 | ```
|
144 |
|
145 | Run `webappengine` with `--config` to set multihost configuration file:
|
146 | ```bash
|
147 | $ webappengine --config "/path/to/your/project/static-config.json"
|
148 | ```
|
149 |
|
150 | or use the API:
|
151 | ```js
|
152 | var webappengine = require('webappengine');
|
153 | var routes = require('./static-config.json');
|
154 |
|
155 | webappengine({
|
156 | routes: routes
|
157 | });
|
158 | ```
|
159 |
|
160 | Visits `http://yourhostname:8000/` will serve `index.html` file as below:
|
161 | ```
|
162 | <h1>WebAppEngine Test Page</h1>
|
163 | ```
|
164 | (See also: [examples/static/index.html](examples/static/index.html))
|
165 |
|
166 | ### Configure multihost settings to run multiple web apps
|
167 | First, checkout [examples/simple/app.js](examples/simple/app.js) and [examples/multihost.json](examples/multihost.json), and copy [examples](examples) to your project folder to kickstart a web application.
|
168 |
|
169 | simple/app.js:
|
170 | ```js
|
171 | var path = require('path'),
|
172 | express = require('express');
|
173 |
|
174 | module.exports = function(options) {
|
175 | options = options || {};
|
176 |
|
177 | var app = express();
|
178 | var serveStatic = require('serve-static');
|
179 | var assetPath = path.resolve(__dirname, 'web');
|
180 |
|
181 | // Enable case sensitivity routing: "/Foo" is not equal to "/foo"
|
182 | app.enable('case sensitive routing');
|
183 | // Disable strict routing: "/foo" and "/foo/" are treated the same
|
184 | app.disable('strict routing');
|
185 |
|
186 | app.use(options.route, serveStatic(assetPath));
|
187 |
|
188 | return app;
|
189 | };
|
190 | ```
|
191 |
|
192 | server-config.json:
|
193 | ```json
|
194 | [
|
195 | {
|
196 | "type": "server",
|
197 | "route": "/simple",
|
198 | "server": "/path/to/your/project/simple/app"
|
199 | }
|
200 | ]
|
201 | ```
|
202 |
|
203 | Run `webappengine` with `--config` to set multihost configuration file:
|
204 | ```bash
|
205 | $ webappengine --config "/path/to/your/project/server-config.json"
|
206 | ```
|
207 |
|
208 | or use the API:
|
209 | ```js
|
210 | var webappengine = require('webappengine');
|
211 | var routes = require('./server-config.json');
|
212 |
|
213 | webappengine({
|
214 | routes: routes
|
215 | });
|
216 | ```
|
217 |
|
218 | Visits `http://yourhostname:8000/simple` will serve `index.html` file as below:
|
219 | ```
|
220 | <h1>WebAppEngine Test Page</h1>
|
221 | ```
|
222 | (See also: [examples/simple/web/index.html](examples/simple/web/index.html))
|
223 |
|
224 | ## Administration UI
|
225 | <i>The administration UI is currently under construction.</i>
|
226 | ### Dashboard
|
227 | TBD
|
228 | ### Change the display language
|
229 | You can change the display language from the <b>Settings</b> menu, it will set the `lang` query string parameter: `?lang={locale}`
|
230 |
|
231 | Here is a list of currently supported locales:
|
232 |
|
233 | Locale | Language
|
234 | ------ | --------
|
235 | de | Deutsch
|
236 | en | English (US)
|
237 | es | Español
|
238 | fr | Français
|
239 | it | Italiano
|
240 | ja | 日本語
|
241 | zh-cn | 中文 (简体)
|
242 | zh-tw | 中文 (繁體)
|
243 |
|
244 | ## License
|
245 |
|
246 | Copyright (c) 2015-2016 Cheton Wu
|
247 |
|
248 | Licensed under the [MIT License](LICENSE).
|