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)](https://coveralls.io/r/cheton/webappengine)
|
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://github.com/cheton/webappengine/blob/master/media/screenshot.png)
|
8 | <i>Note. The administration UI is currently under construction.</i>
|
9 |
|
10 | ## Installation
|
11 | ```bash
|
12 | $ npm install -g webappengine
|
13 | ```
|
14 |
|
15 | ## Usage
|
16 | Run `webappengine` to start the app, and visit `http://yourhostname:8000/` to check if it works:
|
17 |
|
18 | ```bash
|
19 | $ webappengine
|
20 | ```
|
21 |
|
22 | To check what port the app is running on, find the message `Server is listening on 0.0.0.0:8000` from console output.
|
23 |
|
24 | By default the app listens on port 8000, you can use the `PORT` environment variable to determine which port your application should listen on. For example:
|
25 | ```bash
|
26 | $ PORT=80 webappengine
|
27 | ```
|
28 |
|
29 | Set the environment variable `NODE_ENV` to `production` if you are running in production mode:
|
30 | ```bash
|
31 | $ NODE_ENV=production webappengine
|
32 | ```
|
33 |
|
34 | Run `webappengine` with `-h` for detailed usage:
|
35 | ```
|
36 | $ webappengine -h
|
37 |
|
38 | Usage: webappengine [options]
|
39 |
|
40 | Options:
|
41 | -h, --help output usage information
|
42 | -V, --version output the version number
|
43 | -c, --config [filename] set multihost configuration file
|
44 | (default: node_modules/webappengine/app/config/multihost.json)
|
45 | ```
|
46 |
|
47 | ## Getting Started
|
48 |
|
49 | ### Configure multihost settings
|
50 | 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.
|
51 |
|
52 | simple/app.js:
|
53 | ```js
|
54 | var path = require('path'),
|
55 | express = require('express');
|
56 |
|
57 | module.exports = function(options) {
|
58 | options = options || {};
|
59 |
|
60 | var app = express();
|
61 | var serveStatic = require('serve-static');
|
62 | var assetPath = path.resolve(__dirname, 'web');
|
63 |
|
64 | // Enable case sensitivity routing: "/Foo" is not equal to "/foo"
|
65 | app.enable('case sensitive routing');
|
66 | // Disable strict routing: "/foo" and "/foo/" are treated the same
|
67 | app.disable('strict routing');
|
68 |
|
69 | app.use(options.route, serveStatic(assetPath));
|
70 |
|
71 | return app;
|
72 | };
|
73 | ```
|
74 |
|
75 | multihost.json:
|
76 | ```json
|
77 | [
|
78 | {
|
79 | "route": "/simple",
|
80 | "server": "/path/to/your/project/simple/app"
|
81 | }
|
82 | ]
|
83 | ```
|
84 |
|
85 | Run `webappengine` with `--config` to set multihost configuration file, like so:
|
86 | ```bash
|
87 | $ webappengine --config "/path/to/your/project/multihost.json"
|
88 | ```
|
89 |
|
90 | Visits `http://yourhostname:8000/simple` will return a simple page as below:
|
91 | ```
|
92 | WebAppEngine Test Page
|
93 | ```
|
94 | (See also: [examples/simple/web/index.html](examples/simple/web/index.html))
|
95 |
|
96 | ## Internationalization (I18n)
|
97 | ### Change the display language
|
98 | You can change the display language by specifying the `lang` query string parameter: `?lang={locale}`
|
99 |
|
100 | Here is a list of currently supported locales:
|
101 |
|
102 | Locale | Language
|
103 | ------ | --------
|
104 | de | Deutsch
|
105 | en | English (US)
|
106 | es | Español
|
107 | fr | Français
|
108 | it | Italiano
|
109 | ja | 日本語
|
110 | zh-cn | 中文 (简体)
|
111 | zh-tw | 中文 (繁體)
|
112 |
|
113 | ## License
|
114 |
|
115 | Copyright (c) 2015 Cheton Wu
|
116 |
|
117 | Licensed under the [MIT License](https://github.com/cheton/webappengine/blob/master/LICENSE).
|