web.config与angular万能

我想在Azure Web中运行angular色4 univeral。 我部署的代码,但我有一些麻烦与web.config(我认为是这样)。

位于dist文件夹中的server.js,所以我在web.config“dist / server.js”中设置path,但是当server.js运行时,会出现一个错误:

ENOENT:没有这样的文件或目录,打开'D:\ home \ site \ wwwroot \ dist \ dist \ browser \ index.html'

如果我从path中删除“dist”,它将会是404.如果我从中删除“dist”

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

它会给我一个错误:

ENOENT:没有这样的文件或目录,打开'D:\ home \ site \ wwwroot \ browser \ 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}!`); }); 

您的server.js位于“dist”文件夹中。 所以,请更改以下行

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

 const DIST_FOLDER = process.cwd(); 

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