D
D
Dimon Fool2015-07-10 11:03:02
Node.js
Dimon Fool, 2015-07-10 11:03:02

Is it possible to implement such a scenario?

Now I use IAS to host ten simple landing sites that differ only in domain names and six variables (counter number, Yandex validation string, and Google form parameters). Variables are placed in a file server/request.js, from which values ​​are substituted into templates.
Thus, there are ten subdirectories in applicationsand it all works, only making changes to all these sites is a bit inconvenient.
Is it possible to use only one application, bind all ten domain names to it, and substitute variables into the template depending on the requested domain name?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Timur Shemsedinov, 2015-07-10
@dimon_durak

There is nothing complicated about this, I just recommend moving the variables, or rather, they are constants to /init/constants.js , otherwise they are created and lost on /server/requests.js every time. For example like this:

application.constants = {
  'domain1.com': { field1: "value1", ... }
  'domain2.net': { field1: "value1", ... },
    ...
};

And in /server/requests.js they can simply be returned depending on the site domain:
module.exports = function(client, callback) {
  client.cache('10m');  // кешируем на 10 минут
  // отдаем нужный набр переменных для сайта
  callback(application.constants[client.host]);
};

Well, in /config/hosts.js we configure everything for one application:
module.exports = [ '*' ];

D
Dimon Durak, 2015-07-10
@dimon_durak

Thanks, it worked.
True, it worked partially.
First, with caching enabled, the second request breaks everything with the following output:

2015-07-10T11:43:36.864Z
Master(5932/C1N0)
TypeError: undefined is not a function
  Client.sendCache (impress.client.js:602:62)
  Client.processing (impress.client.js:375:62)
  impress.client.js:261:16
  Client.detectRealPath (impress.client.js:712:91)
  impress.client.js:260:14
  Client.restoreSession (impress.client.js:339:17)
  Client.dispatch (impress.client.js:259:12)
  impress.application.js:487:21
  Client.static (impress.client.js:821:28)
  EventEmitter.application.dispatch (impress.application.js:460:18)
  Server.impress.dispatcher (impress.js:691:26)
  Server.emit (events.js:110:17)
  HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:491:12)
  HTTPParser.parserOnHeadersComplete (_http_common.js:111:23)
  Socket.socketOnData (_http_server.js:343:22)
  Socket.emit (events.js:107:17)
  readableAddChunk (_stream_readable.js:163:16)
  Socket.Readable.push (_stream_readable.js:126:10)
  TCP.onread (net.js:538:20)
Impress shutting down

Without caching, it works as it should, but I just don’t know what to do with requests for www.domain.ru. Of course, you can duplicate an object with an 'domain.ru'object 'www.domain.ru'in init/constants.js(and it works), but something tells me that this is not a very beautiful solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question