Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to run different node app on server different domains

var http = require('http'),
    httpProxy = require('http-proxy');

var proxy_web = new httpProxy.createProxyServer({
        target: {
            host: 'localhost',
            port: 8080
        }
    });

    var proxy_api = new httpProxy.createProxyServer({
        target: {
            host: 'localhost',
            port: 8081
        }
    });

    http.createServer(function(req, res) {
        if (req.headers.host === 'http://www.domain.com') {
            proxy_web.proxyRequest(req, res);
            proxy_web.on('error', function(err, req, res) {
                if (err) console.log(err);
                res.writeHead(500);
                res.end('Oops, something went very wrong...');
            });
        } else if (req.headers.host === 'http://api.domain.com') {
            proxy_api.proxyRequest(req, res);
            proxy_api.on('error', function(err, req, res) {
                if (err) console.log(err);
                res.writeHead(500);
                res.end('Oops, something went very wrong...');
            });
        }
    }).listen(80);
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript check if number is a power of 2 
Javascript :: check if string is datestring javascript 
Javascript :: drawer navigation set width react native 
Javascript :: split date in javascript 
Javascript :: javascript base64 encode file input 
Javascript :: vue dev server proxy not working 
Javascript :: react delete button onclick 
Javascript :: Unexpected token a in JSON at position 
Javascript :: update formgroup value angular 
Javascript :: react native run on device command line 
Javascript :: javascript on image load 
Javascript :: how to pretty formatjson value on terminal ruby 
Javascript :: javascript window.history.pushstate 
Javascript :: devtools failed to load sourcemap when debugging react native 
Javascript :: get content of textarea javascript 
Javascript :: exec js 
Javascript :: jquery remove attribute 
Javascript :: for of with index 
Javascript :: get child routes using parent in angular 
Javascript :: refresh page on div click 
Javascript :: json merge 
Javascript :: store id of an element jquery 
Javascript :: javascript date get future 15 minutes 
Javascript :: how do i make a link to direct me to a new page when i click on a button in react 
Javascript :: jquery replace h1 with h2 
Javascript :: add access-control-allow-origin in node js 
Javascript :: how to loop through array of numbers in javascript 
Javascript :: xmlhttprequest get request 
Javascript :: get url params with js 
Javascript :: Facebook passport Oauth authenticate strategy 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =