2017-09-13 73 views
1

我想在Azure Web中運行角色4 univeral。我部署了代碼,但是我在web.config中遇到了一些麻煩(我認爲是這樣)。位於帶角度通用的web.config

的server.js在蒸餾水文件夾,所以我設置在web.config中 「DIST/server.js」 路徑,但server.js運行時,它提供了一個錯誤:

ENOENT:沒有這樣的文件或目錄中,打開'D:\ home \ site \ wwwroot \ dist \ dist \ browser \ index.html'

如果我從路徑中刪除「dist」,它將會是404.如果我從中刪除「dist」

const DIST_FOLDER = join(process.cwd(), 'dist'); in server.js 

它會給我一個錯誤:

ENOENT:沒有這樣的文件或目錄,打開 'd:\家\網站\ wwwroot的\瀏覽器\ index.html在'

或者雙DIST,或根本沒有DIST可言。

的web.config文件看起來是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.webServer> 
    <webSocket enabled="false" /> 
    <handlers> 
     <add name="iisnode" path="dist/server.js" verb="*" modules="iisnode"/> 
    </handlers> 
    <rewrite> 
     <rules> 
     <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true"> 
      <match url="^dist/server.js\/debug[\/]?" /> 
     </rule> 
     <rule name="StaticContent"> 
      <action type="Rewrite" url="public{REQUEST_URI}"/> 
     <rule name="DynamicContent"> 
      <conditions> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/> 
      </conditions> 
      <action type="Rewrite" url="dist/server.js"/> 
     </rule> 
     </rules> 
    </rewrite> 
    <security> 
     <requestFiltering> 
     <hiddenSegments> 
      <remove segment="bin"/> 
     </hiddenSegments> 
     </requestFiltering> 
    </security> 
    <httpErrors existingResponse="PassThrough" /> 
    </system.webServer> 
</configuration> 

的server.js代碼:

const PORT = process.env.PORT || 8080; 
const DIST_FOLDER = join(process.cwd(), 'dist'); 

const app = express(); 

const template = readFileSync(join(DIST_FOLDER, 'browser', 'index.html')).toString(); 
const { AppServerModuleNgFactory } = require('main.server'); 

app.engine('html', (_, options, callback) => { 
    const opts = { document: template, url: options.req.url }; 

    renderModuleFactory(AppServerModuleNgFactory, opts) 
    .then(html => callback(null, html)); 
}); 

app.set('view engine', 'html'); 
app.set('views', 'src'); 

app.get('*.*', express.static(join(DIST_FOLDER, 'browser'))); 

app.get('*', (req, res) => { 
    res.render('index', { req }); 
}); 

app.listen(PORT,() => { 
    console.log(`listening on http://localhost:${PORT}!`); 
}); 

回答

0

server.js位於 「DIST」 文件夾中。所以,請更改以下行

const DIST_FOLDER = join(process.cwd(), 'dist'); 

const DIST_FOLDER = process.cwd(); 
+0

問題是它使得錯誤「ENOENT:沒有這樣的文件或目錄,打開D:\ home \ site \ wwwroot \ browser \ index.html」,根本沒有dist文件夾。 – RaShe

0

我想通了,而不是process.cwd(),我應該使用__dirname。