express.static生成未捕获的SyntaxError:意外令牌<

时间:2019-05-27 09:17:30

标签: javascript asp.net angular express universal

我在iis中设置通用角度,该解决方案在本地运行良好,当我部署时出现Uncaught SyntaxError:意外令牌<。 问题是由于express.static我似乎无法正确的路径。

server.js的片段:

var app = express();
var PORT = process.env.PORT || 5618;
var DIST_FOLDER = path_1.join(process.cwd(), 'ClientApp/dist/browser');

app.set('view engine', 'html');
app.set('views', DIST_FOLDER);
// Example Express Rest API endpoints
// app.get('/api/**', (req, res) => { });
// Serve static files from /browser

app.get(express.static(path.join(DIST_FOLDER), {
   maxAge: '1y'
}));


// All regular routes use the Universal engine
app.get('*', function (req, res) {
    res.render('index', { req: req });
});

注意:当我从web.config中删除重写时,我的应用程序可以正常工作(没有预渲染) 这是我的网络配置:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
        <add name="iisnode" path="server.js" verb="*" modules="iisnode" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\Coiner.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
      <rewrite>
        <rules>
            <rule name="myapp">
                <match url="/*" />
                <action type="Rewrite" url="server.js" />
            </rule>
        </rules>
    </rewrite>
    </system.webServer>
  </location>
</configuration>
<!--ProjectGuid: e64f9183-0a19-41c8-9f3a-9d8c5377915b-->

这是我的应用程序的结构:

  • server.js
  • web.config
  • ClientApp / dist / browser / index.html
  • ClientApp / dist / browser / assets / images,js,i18n

0 个答案:

没有答案