A
A
Al2016-08-15 11:46:38
Node.js
Al, 2016-08-15 11:46:38

Handling multiple domains with one express application, is it possible?

The essence of the situation is this. There are several simple sites (for example, these are blogs / pages on different topics), they have a common database, and a common admin panel. For example, 10 blogs, each has its own domain (blog1.com, blog2.com, blog3.com, ...), and there is an admin panel (where we can upload articles, etc.), for example, it hangs on a sub-domain of some another domain (admin.my-root-blog.com). So, my-root-blog.com and admin.my-root-blog.com are broken into sub-applications using the subdomain module

//общие настройки
let app = express();
app.use(subdomain({base:host,removeWWW:true }));
app.engine("ejs",require("ejs-locals"));
app.set('view engine', 'ejs');
// и др.
// далее настройка основного приложения для домена my-root-blog.com

let admin = express();
// далее настройка admin 

//Здесь подключаем роуты:
require("router/root")({app:app,admin:admin});

//под-приложение админ-панели вешаем на суб-домен, должно быть доступно по адресу: admin.my-root-blog.com
app.use("/subdomain/admin", admin);

//тут еще какие-то настройки ...

module.exports = app;

So, with the sub-domain, it's clear - this is a common admin panel. Now the actual question is how to add some other domains (blog1.com, blog2.com, blog3.com, ...) to the same sub-applications as with a sub-domain, so that all this remains one application, but for each domain could define its own folder with resources, its own template-engine, and so on. just like it's done for the sub-domain?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Al, 2016-08-15
@Sanu0074

Did everything with ' express-vhost'

K
Kirill, 2016-08-15
@kirill89

Look towards the vhost module . Also found examples of using .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question