2016-08-30 143 views
0

當我嘗試直接從Microsoft Azure控制檯手動運行app.js文件時,我遇到以下錯誤。爲什麼? app.js在我的本地主機上正常工作。 enter image description here將nodejs應用程序部署到Microsoft Azure時出錯

這是我的app.js文件:

'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); 
    }); 
}); 

(JavaScript代碼來自swagger.io)

回答

1

你不必開始Azure上運行的應用程序的Node.js通過在Azure上手動執行命令node app.js來運行Web應用程序。由於您的應用程序的根目錄中已經有一個入口文件app.jsserver.js和一個IIS web.config,您可以通過URL直接瀏覽您的nodejs應用程序。

我測試了示例項目https://github.com/apigee-127/swagger-tools/tree/master/examples/2.0,它應該和你的類似。它在我身邊正常工作。

請嘗試直接在瀏覽器上瀏覽您的應用程序。

任何更新,請隨時讓我知道。

相關問題