我想在Azure Web Appp上運行一個非常簡單的node.js服務器來爲單個頁面應用程序提供服務。服務器將提供靜態頁面,並且始終爲頁面請求服務器'index.html',因爲所有路由都在客戶端完成。在Azure Web App上運行Node.js
所有工作絕對完美,但在部署到Azure時,任何頁面請求都會導致「您正在查找的資源已被刪除......」,這表明節點服務器未被命中。
我使用Koa作爲服務器,server.js在這裏;
var Koa = require('koa');
var convert = require('koa-convert');
var helmet = require('koa-helmet');
var historyApiFallback = require('koa-connect-history-api-fallback');
var serve = require('koa-static');
var app = new Koa();
// This rewrites all routes requests to the root /index.html file
// (ignoring file requests). If you want to implement isomorphic
// rendering, you'll want to remove this middleware.
app.use(convert(historyApiFallback({
verbose: false
})));
// Serving ~/dist by default. Ideally these files should be served by
// the web server and not the app server, but this helps to demo the
// server in production.
app.use(convert(serve(__dirname)));
app.use(helmet());
var server = app.listen(3000);var Koa = require('koa');
var convert = require('koa-convert');
var helmet = require('koa-helmet');
var historyApiFallback = require('koa-connect-history-api-fallback');
var serve = require('koa-static');
var app = new Koa();
// This rewrites all routes requests to the root /index.html file
// (ignoring file requests). If you want to implement isomorphic
// rendering, you'll want to remove this middleware.
app.use(convert(historyApiFallback({
verbose: false
})));
// Serving ~/dist by default. Ideally these files should be served by
// the web server and not the app server, but this helps to demo the
// server in production.
app.use(convert(serve(__dirname)));
app.use(helmet());
var server = app.listen(3000);
我已經包含在部署的package.json一些文件表明,要求節點程序包將被自動安裝(KOA等),但它不看起來好像已經奏效。
任何想法?
我可以在上面的代碼中看到重複的代碼。 'var server = app.listen(3000);'後刪除代碼並再次嘗試 –
道歉,我明顯粘貼兩次,因此重複(這是一個深夜)。不幸的是我不能編輯這個帖子,但是實際的版本沒有重複。 – PizzaTheHut
我已經將KOA應用部署到天藍色,沒有任何錯誤。我認爲你可以參考文章https://azure.microsoft.com/en-us/documentation/articles/web-sites-nodejs-develop-deploy-mac將你的代碼移動到git,然後將其移動到天藍。記得要配置好你的package.json。我通過cmd'npm install koa'安裝koa並將其寫入package.json,如下所示:「dependencies」:{ 「express」:「3.2.6」, 「jade」:「*」, 「koa」: 「*」 }。最好使用'app.listen(process.env.PORT || 3000);'在你的app.js中替換'app.listen(3000);'。 –