I have 3 domains configured in my nodeJS app.
api.example.com
, www.example.com
, admin.example.com
To build this app in SOA way, I have different routes for API front and admin.
so for routes
www.example.com/myAddresses/{customerId}
var httpProxy = require('http-proxy');
var proxy = new httpProxy.RoutingProxy();
app.get('/myAddresses/:customerId, function(request, response) {
// I can use express proxy to call API.
proxy.proxyRequest(req, res ,{
host: 'api.example.com',
port: 80
});
});
The problem with proxy I see that is proxy makes an HTTP request, which is an extra overhead. I'd like to make an internal code call.
A great implementation for same I have seen with Laravel
using a package DINGO
You can make an static function call in laravel like
Dingo::API('/myAddresses', $request)
Can anyone point me right direction to implement this feature?
EDIT
So I am already using the given approach by @Krzysztof Sztompka
. I'll explain this more. My Express JS app has three subapps api
, front
& admin
. In each module I have three sections for routes and controllers for each app respectively. Now the idea may not be only to call one route of app from same app, e.g. front route --> front route.
I only want to call Route of API app from web/admin apps. calling a function of a model is not a problem but as Krzysztof rightly said it won't be SOA approach. If you guys can just help me how to call route (and if possible call route of different app) from my controller that would be a great help.