For example, if you start a static server like this:

var http = require('http'); var static = require('node-static'); var file = new static.Server('dir1'); http.createServer(function(req, res) { file.serve(req, res); }).listen(80); console.log('Server running on port 80'); 

when a person enters mysite.ru data from the dir1 folder will be sent to him.

How to write the similar code, but that files were issued when entering a subdomain.mysite.ru ?

  • and dns properly configured and knows about this domain? - KoVadim
  • @KoVadim, yes he knows. - pank
  • if both domains refer to the same address, then you need to check with the handles - like this: http.createServer(function(req, res) { var host = req.get('host'); if (host === 'subdomain.mysite.ru') file.serve(req, res); }).listen(80); - KoVadim
  • @KoVadim; Doesn't work: TypeError: req.get is not a function . - pank
  • 3
    there is also a beautiful solution - put apache or nginx in front of the node and set up proxying. - KoVadim

0