Answer the question
In order to leave comments, you need to log in
Is it possible to generate subdomains on nodejs?
Is it possible to generate subdomains on nodejs with content rendering?
Is it possible to implement this structure on nodejs:
1. The user accesses 'subdomian.domian.com';
2. Nodejs takes templated html, inserts data according to the domain;
3. Generates and renders a rendered page to the user.
How difficult is it? And is it worth neglecting this method?
Answer the question
In order to leave comments, you need to log in
I would use nginx before nodejs.
We listen to domains and all its subdomains and pass an additional header to the node
server {
listen *:80;
server_name domian.com *.domian.com;
set $subdomain "";
if ($host ~ ^(.*)\.domian\.com$) {
set $subdomain $1;
}
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header X-Subdomain $subdomain;
}
}
var express = require('express');
var app = express();
app.get('/', function(req, res) {
// здесь что-то делаем с этим заголовком
res.end('Subdomain: ' + req.headers['x-subdomain']);
});
app.listen(3000);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question