Hello ![]()
Ok so behind this clickbait-like title, I actually want to share something nice with the community ![]()
I found a nice way to create as many NodeJS server as I want, (a new server being created within less than a minute) starting from an existing one.
Spoiler Alert : In fact it’s only one (paid) server in total of course, there is nothing FREE ![]()
So, here is the trick :
- I have a domain (I pay) at AWS : tricotools.com
- Creating any subdomain redirection is FREE. For example :
- I redirect all subdomains toward the same server, using my own
HTTPS certificate
Now, here is the nice part :
- On the main server, I have one
folderfor eachchild server. Each folder contains exactly the content of a “normal” NodeJS server : a main filemain.js, and its dependencies (public/folder,assets/, or anything…) - In the root folder, I have a very simple
parentserver :
// Requirements
const express = require('express');
const vhost = require('vhost');
const port = process.env.PORT;
const hover_app = require('./hover/main.js').hover_app;
const tchat_app = require('./tchat/main.js').tchat_app;
const gpu_app = require('./gpu/main.js').vr_app;
const game_app = require('./game/main.js').game_app;
const vr_app = require('./vr/main.js').vr_app;
// Express
const App = express();
// Forwarding depending on subdomain
App.use(vhost('hover.tricotools.com', hover_app));
App.use(vhost('tchat.tricotools.com', tchat_app));
App.use(vhost('gpu.tricotools.com', gpu_app));
App.use(vhost('game.tricotools.com', game_app));
App.use(vhost('vr.tricotools.com', vr_app));
// Listen
App.listen(port);
The above code redirects automatically each request and connexion toward the considered server, based on the subdomain URL the user is arriving from
On the child server side, I simply export an Express App :
// Express
const App = express();
// MiddleWares
App.use('middleware_01', params_01);
App.use('middleware_02', params_02);
App.use('middleware_03', params_03);
// Export this App
exports.hover_app = App;
And that’s it ![]()
Is means that now when I have a “new idea”, and want to give it a try over a new “fresh” server (free of anybullshit from another game or whatever) I need to :
- Copy a folder and rename it (5 seconds)
- Add a new
vhostline in the parent server (5 seconds) - Commit & Push (20 seconds)
- Connect to AWS Route 53 and redirect this new name (30 seconds)
Total : 1 minute for a new server up and running, over HTTPS ![]()
Maybe all this bullshit sounds obvious for many of you, but on my side I’m quite happy with this new trick. The total RAM used is a few MB in total, the CPU is almost at 0% most of the time… What I mean is, unless I set up a multiplayer game with thousands of people, it does not add any “charge” to the bill ![]()
++
Tricotou