So I'm trying to build a simple PaaS for Node apps (http://www.github.com/darrensmith/baseplatform) and I'm getting some really strange behaviour.
Basically - you can run BasePlatform on your host and it starts up a proxy server on port 8080 using http-proxy and an instance of Swaggerize-express on port 8180. Initially it proxies all requests on port 8080 through to 8180 which is the API to install new apps.
You can upload an app and specify a domain name that has its DNS pointing at the same host (localhost for purpose of testing) and based on that domain it will proxy requests through to the app that is running on an alternate port.
So I created a second swaggerize-express app and uploaded it in to BasePlatform running on port 8005. However when I try and view the Swagger JSON that is automatically generated (http://localhost:8005/api/v1/api-docs) for the app running on port 8005 I get the JSON for the default app running on port 8180.
If I start the app independently and hit port 8005 I get the correct JSON.
I'm not understanding how a node process running on one port of my host is interferring with the node process running on the other and am looking for some insight.
Note - this is me trying to hit the installed app's json directly on the port that it was started on. If I try viewing it on port 8080 (via the proxy) I get the same behaviour. My static routes that aren't automatically being handled by Swaggerize are working as expected - there only seems to be crossover between the swaggerize handled routes.
Any help would be greatly appreciated!
Figured it out!
I implicitly left the current working directory as that of the parent process (BasePlatform) when launching the child process:
const fork = require('child_process').fork;
app.locals.settings.deployedProcesses[oldAppId+'-'+latestDeployId] = fork('./deployments/'+oldAppId+'-'+latestDeployId+'/server.js');
In doing so the Swaggerize router of the child process was picking up the swagger.yaml file of the parent process (because it was stuck in the parent's current working directory) instead of its own.
I revised it to set the current working directory to that of the child process:
const fork = require('child_process').fork;
app.locals.settings.deployedProcesses[oldAppId+'-'+latestDeployId] = fork('server.js',[],{
cwd: './deployments/'+oldAppId+'-'+latestDeployId
});