Reputation: 295
I am catching the following error when I try to manually run the app.js file directly from the Microsoft Azure Console. Why? The app.js works fine on my localhost.
This is my app.js file:
'use strict';
var app = require('connect')();
var http = require('http');
var swaggerTools = require('swagger-tools');
var jsyaml = require('js-yaml');
var fs = require('fs');
var serverPort = process.env.PORT || 3000;
// swaggerRouter configuration
var options = {
swaggerUi: '/swagger.json',
controllers: './controllers',
useStubs: process.env.NODE_ENV === 'development' ? true : false // Conditionally turn on stubs (mock mode)
};
// The Swagger document (require it, build it programmatically, fetch it from a URL, ...)
var spec = fs.readFileSync('./api/swagger.yaml', 'utf8');
var swaggerDoc = jsyaml.safeLoad(spec);
// Initialize the Swagger middleware
swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) {
// Interpret Swagger resources and attach metadata to request - must be first in swagger-tools middleware chain
app.use(middleware.swaggerMetadata());
// Validate Swagger requests
app.use(middleware.swaggerValidator());
// Route validated requests to appropriate controller
app.use(middleware.swaggerRouter(options));
// Serve the Swagger documents and Swagger UI
app.use(middleware.swaggerUi());
// Start the server
http.createServer(app).listen(serverPort, function () {
console.log('Your server is listening on port %d (http://localhost:%d)', serverPort, serverPort);
console.log('Swagger-ui is available on http://localhost:%d/docs', serverPort);
});
});
(The javascript code comes from swagger.io)
Upvotes: 0
Views: 153
Reputation: 13918
You don't have to start the node.js application running on Azure Web Apps via executing the command node app.js
manually on Azure. As you have already an entrance file app.js
or server.js
and an IIS web.config
in the root directory of your application, you can directly browse your nodejs application via the URL.
I tested the example project at https://github.com/apigee-127/swagger-tools/tree/master/examples/2.0 which should be similar with yours. It works fine on my side.
Please try to browse your application directly on browser.
Any update, please feel free to let me know.
Upvotes: 1