Skip to content
Ivo Yankulovski edited this page Sep 21, 2019 · 30 revisions

Localhost development

Configure hosts file if you have to /etc/hosts and add your subdomain:

127.0.0.1 localhost
127.0.0.1 my.nodewebsite.com.localhost

Open terminal in the ProtoSS node server folder

  • Configure basic ProtoSS server

  • Execute node index.js and start the server.

  • Configure module Subserver

  • create or copy stats.json in index.js folder

  • check modules\Subserver_stats.json

  • Execute node index.js and start the subserver.

  • Configure example.js

  • check Subserver configuration

  • Execute node example.js and start the example.

  • Configure your own application.js

  • check example.js configuration

  • configure stats.json with the right server module, you might use your own implementation

  • server starts automatically, you might choose to stop it and execute different logic

  • several applications requiring the same index.js will load and share the same stats.json and therefor base server module

  • one application may create several different instances on different ports depending on implementation, sharing static properties with all other servers and applications pointing to the same folder

  • Execute node application.js and start your app.

  • Swap of ports in applications

  • starting new application based on server from the same folder will throw an error

  • in each of your applications sharing server folder close and listen the http server using your own port, you might choose to load it from a separate .json

  • use htport: 0 in your stats.json to listen on random port, or negative integer htport: -1 to disable auto listen in index.js

  • code example:

var myport = 5000;
var protossche = require('./index.js');
protossche.serverche.htserv.close().listen(myport);

Configure HTTPS server

  • set https: true in stats.json
  • place key.pem and cert.pem in your server folder of index.js
  • or specify httpsop Object in stats.json for any additional Node server configuration based on official documentation
  • special https options keys: keyPath, certPath, pfxPath, caPath

Apache Configuration

Load or enable in your httpd file the proxy modules:

LoadModule proxy_module modules/mod_proxy.so  
LoadModule proxy_http_module modules/mod_proxy_http.so  

Enable HTTP/2, if you need it locally, node will leverage the protocol:

LoadModule proxy_http2_module modules/mod_proxy_http2.so  

LoadModule http2_module modules/mod_http2.so  

ProtocolsHonorOrder On  
Protocols h2 http/1.1  

Enable SSL, if you need it locally, and configure the server keys:

LoadModule ssl_module modules/mod_ssl.so

Generate self-signed certificates online or offline.
Configure listen ports in httpd:

Listen 0.0.0.0:80
Listen [::0]:80

Listen 0.0.0.0:443
Listen [::0]:443

Enable SSL engine in your vhost configuration and add the secure port:

<VirtualHost *:80 *:443>
	...
	SSLEngine on
	SSLCertificateKeyFile "Drive:\path\to\certs\my.nodewebsite.com.localhost.key"
	SSLCertificateFile "Drive:\path\to\certs\my.nodewebsite.com.localhost.cert"
	...
</VirtualHost>

Add to your vhost configuration of ServerName my.nodewebsite.com.localhost the proxy line:

ProxyPass /node http://my.nodewebsite.com.localhost:8888/node  

/node is your base url, you might omit it in the node url
http://my.nodewebsite.com.localhost is your node host, use raw http for performance instead of https, ssl can be enforced from the next server layer of Apache/NGINX
8888 is your node listen port

GZIP transfer is enabled per header content-type and requires deflate module.

LoadModule deflate_module modules/mod_deflate.so

Create folder node in the root of your domain and create .htaccess with the following code:

RewriteEngine On
RewriteBase /

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/json

AddOutputFilterByType DEFLATE can exist in several places including root .htaccess
or main httpd file, if you have access to it

AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css text/javascript application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript application/json

Sample vhost for localhost:

<VirtualHost *:80>
	ServerName my.nodewebsite.com.localhost
	ServerAlias my.nodewebsite.com.localhost
	DocumentRoot "Drive:\path\to\website"
	ProxyPass /node http://my.nodewebsite.com.localhost:8888/node
	<Directory "Drive:\path\to\website">
		Options +Indexes +Includes +FollowSymLinks +MultiViews
		AllowOverride All
		Require local
	</Directory>
</VirtualHost>

Caching of assets depends on all the other configurations and requires expires_module:

LoadModule expires_module modules/mod_expires.so

Add to .htaccess:

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType video/mp4 "access 1 month"
ExpiresByType video/webm "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/x-icon "access 1 month"
ExpiresByType font/woff "access 1 month"
</IfModule>

Caching of JS/CSS files on user machines is not promoted due to security reasons and requires additional version mechanism.

The Apache configuration can be modified to work with NGINX server.

Node.js works with PHP simultaneously. Logic is separated by folder.

Now all of your nodes are fully automated with GZIP, SSL, CACHE, H2

Clone this wiki locally