javascript - How to create subdomain for user in node.js -


i'd share user information @ username.domain.com @ application. subdomain should available after user create account.

i have found nice module useful in case: express subdomain

how can using module? maybe module isn't useful 1 should use?

as mentioned in op comments, using nginx webserver in front of node option, since secure way listen 80 port. can serve static files (scripts, styles, images, fonts, etc.) more efficiently, have multiple sites within single server, nginx.

as question, nginx, can listen both example.com , subdomains, , pass subdomain node custom request header (x-subdomain).

example.com.conf:

server {     listen          *:80;     server_name     example.com   *.example.com;      set $subdomain "";     if ($host ~ ^(.*)\.example\.com$) {         set $subdomain $1;     }      location / {         proxy_pass          http://127.0.0.1:3000;         proxy_set_header    x-subdomain     $subdomain;     } } 

app.js:

var express = require('express'); var app = express();  app.get('/', function(req, res) {     res.end('subdomain: ' + req.headers['x-subdomain']); });  app.listen(3000); 

this brief example of using nginx , node together. can see more detailed example explanation here.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -