Node Atlas NodeAtlas

The Progressive Server-side JavaScript Framework

  • Simple set-up

    You know HTML & CSS?
    But not JavaScript?

    Quickly create multilingual websites effortlessly with simple routes, views or variations.

  • Scalable website

    JavaScript client-side Expert?
    Ready to embrace Node.js?

    Gradually improve your base as you need by using controllers, models or modules.

  • Agnostic client side

    Already your Front-end habits?
    You use Data Binding?

    From Vanilla to jQuery and going through Vue, Angular or React: use your favorite tools!

Production Environment

It's a good thing to develop, but it's time to run your website or apps on online production server. See this examples.

IMPORTANT : you must use the "cache": true option in the production's webconfig to allows engine to be optimised or set your NODE_ENV environment variable to production.


NOTE : it's possible your proxy on production not capable to use websockets. In this case, the transport should be limited like this "socketServerOptions": { transports: ['polling'] } (in default without this value, transports are tested progressively like this { transports: ['polling', 'websocket'] }.

In a Windows Server environment with iisnode

In a Windows Server 2013 environment with IIS8 the requirements are:

  1. Install the node.exe executable able to run JavaScript code.
  2. Install the IIS8 UrlRewrite module to map pages executed to an output URL.
  3. Install the IIS8 issnode module to read web.config and to manage the website (IIS Application Pool Management, start/stop website, etc...).

Create application

In IIS8, create a web site and create an Application.

The content of your application will be the site mixed with that of NodeAtlas. So that means this:

node-atlas/
├─ node_modules/
│  ┊┉
├─ languages/
│  ┊┉
│  └─ default.json
┊┉
└─ index.js
site-hello-world/
├─ assets/
│  ┊┉
├─ views/
│  └─ index.htm
└─ webconfig.json

becomes this:

site-hello-world/
├─ node_modules/
│  ┊┉
├─ languages/
│  ┊┉
│  └─ default.json
┊┉
├─ assets/
│  ┊┉
├─ views/
│  └─ index.htm
├─ index.js
└─ webconfig.json

You will add to this set of files, additional file named web.config whose content is:

<configuration>
    <system.webServer>
        <handlers>
            <add name="iisnode" path="node-atlas.js" verb="*" modules="iisnode" />
        </handlers>
        <rewrite>
            <rules>
                <rule name="LogFile" patternSyntax="ECMAScript" stopProcessing="true">
                     <match url="^[a-zA-Z0-9_\-]+\.js\.logs\/\d+\.txt$"/>
                </rule>
                <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url="^node-atlas.js\/debug[\/]?" />
                </rule>
                <rule name="StaticContent">
                     <action type="Rewrite" url="assets{REQUEST_URI}"/>
                </rule>
                <rule name="DynamicContent">
                     <conditions>
                          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
                     </conditions>
                     <action type="Rewrite" url="node-atlas.js"/>
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

to obtain:

site-hello-world/
├─ node_modules/
│  ┊┉
├─ languages/
│  ┊┉
│  └─ default.json
┊┉
├─ assets/
│  ┊┉
├─ views/
│  └─ index.htm
├─ index.js
├─ webconfig.json
└─ web.config

It will just have to click on "Browse " in your IIS8 action panel. You can now manage your website (start / stop / Pool Recycling) like any other IIS8 application.

webconfig example

An example for a production webconfig:

{
    "urlPort": 80,
    "httpPort": 7777,
    "httpHostname": "www.example.com",
    "routes": {
        ...
    }
}

In a Unix environment with forever

This requires:

  1. Install the node.exe executable able to run JavaScript code.
  2. Install the CLI tool forever manager for your websites continuously (start, stop, restart, etc.).
  3. Running in addition of your websites a reverse-proxy running on port 80 for all applications.

Some forever commands

To manage a new website in continues to be used the command:

$ forever start </path/to/>node-atlas/ --path </path/to/your/website/directory/>

To stop it, localise the uid with the list forever command

$ forever list

and then use the command:

$ forever stop <uid>

or <uid> is the uid of running website.

webconfig example

An example for a production webconfig:

{
    "urlPort": 80,
    "httpPort": 7777,
    "httpHostname": "www.example.com",
    "routes": {
        ...
    }
}

You will then use a reverse proxy to make your site accessible on port 80.

In a Unix environment with NGINX

This is an example of NGINX's configuration:

## Server an.example.fr

upstream websocket {
    server Ip_backend:7777;
}

server {

    listen   80;
    server_name an.example.fr;

        keepalive_timeout    60;

    access_log on;

        access_log /var/log/nginx/access.log logstash;
    error_log /var/log/nginx/error-an.example.fr.log;

    location /socket.io/ {
            proxy_pass http://websocket;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
    }

    location / {
        proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;

            proxy_pass http://websocket;
        proxy_read_timeout 300;
        proxy_connect_timeout 300;
        proxy_redirect off;

    }

    error_page 400 401 402 403 405 406 407 408 409 410 411 412 413 414 415 416 417 500 501 502 503 504 505 506 507 /error.html;

    location = /error.html {
            root /var/www/nginx-default;
    }
}

Ip_backend must be replaced by your private subnetwork IP. That can be 127.0.0.1 if node run in same server as NGINX.

websocket should be replaced by any word, it will be also moddify the proxy_pass. It must be unique to each node.

Proxy

Bouncy

Bouncy is an example of reverse-proxy that you can use to run various NodeAtlas websites (with other types of websites) together on the same port (80).

You can for example:

  • run 3 Node.js apps on ports 7777, 7778 and 7779 with forever,
  • and besides launching a apache server on port 81

and make all your websites accessible behind domain names on port 80 with Bouncy example.

Here is a sample configuration with Bouncy:

global-server.js

var bouncy = require('bouncy');

var server = bouncy(function (request, response, bounce) {
    if (request.headers.host === 'beep.example.com') {
        bounce(7777);
    }
    else if (request.headers.host === 'blup.example.com') {
        bounce(7776);
    }
    else if (request.headers.host === 'boop.example.com') {
        bounce(81);
    }
    else {
        response.statusCode = 404;
        response.end('no such host');
    }
});

server.listen(80);

and you can start with:

$ forever start </path/to/>global-server.js

More information about Bouncy