microservices - How to listen two micro services on same port in Node.js -
i new micro service. want create 1 application 2 micro services. don't know how listen both (or more) micro services on same port make 1 application. there tutorial pages available in online ? please suggest me blogpost or tutorial pages or me create application 2 micro services.
i trying create bus booking application has 2 services,
- bus service (which gives bus names & availability)
- user service (which gives & connect user details bus).
i created 2 two nodejs application. need know how combine 2 1 application (with microservice).for can't listen 1 port.
if going use 1 port, need have way distinguish between requests each. if identified port number (instead of, eg, each having different path or domain), have change access url (or header) in way.
given that, can use npm module, express, distinguish between number of request types interpreting request.
you might have:
service1.com , service2.com both pointing xxx.xxx.xxx.xxx:2020. distinguish these examining request object.
eg,
app.get(/.*/, function(request, response, next){ switch(request.headers.host){ case 'service1.com': //some stuff break; case 'service2.com': //some stuff break; } });
or, if domain.com/service1 , domain.com/service2
app.get(/service1/, function(){/*some stuff*/}); app.get(/service2/, function(){/*some stuff*/});
Comments
Post a Comment