Mark Mark - 5 months ago 53
Node.js Question

cannot start nodejs web api hosted in Azure

Learning

nodejs
and started to created my own restful API using restify.

I have created a very simple
server.js
file which contains basically a hello world type example starting up like:

server.post('/api/messages', servicemanager.verifyFramework(), servicemanager.listen());

server.get(/.*/, restify.serveStatic({
'directory': '.',
'default': 'index.html'
}));

server.listen(process.env.port || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});


which works fine locally. I cant hit http://localhost:3978 and I can test my API calls just fine calling http://localhost:3978/api/messages.

I have deployed my code into bitbucket and now I want to host these APIs in Azure using
App Services
.

My project structure is like so:

/topfolder
-/myproject
-/node_modules
-/node_modules...
server.js
package.json
index.html


When I setup the new app service in Azure, I can see that the deployment receives the code from BB, but the service never responds to my requests.

I have setup the home path of the app to live in:
/site/wwwroot/topfolder/myproject
and I can see the
index.html
when I navigate to http://myproject.azurewebsites.net so thats good.

I actually get a 404 error:
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.


There are heaps of examples of how to setup continuous deployment using bitbucket and for the most part, they all seem to work, but my
server.js
file doesnt seem to be the getting called or starting up.

How can I debug whats going on here?

Is the
packages.json
file used in this scenario by Azure?

Thanks.

Answer

As the root directory path of the application hosted on Azure App Services, is D:\home\site\wwwroot. And about the nodejs application, the Azure fabric will find the entrance script in root directory like server.js. And the requests are handled via web.config in root directory. If there is missing server.js or web,config file, you will occur 404 error.

You can try to modify or your application's structure, like to:

-/node_modules
  -/node_modules...
server.js
package.json
index.html

Then, you deploy your application to Azure via GIT or from BB, the Azure deployment task will run command npm install and generate the web.config wile in the root directory.

Any further concern, please feel free to let me know.