如何使用Azure + IISNode + Express为React应用程序构建web.config

时间:2018-08-25 19:58:30

标签: node.js reactjs azure express

我按照本教程构建了我的React应用 https://daveceddia.com/create-react-app-express-backend/https://daveceddia.com/deploy-react-express-app-heroku/。我知道我不会发布到Heroku,因为我正在使用azure Web应用程序服务,但是由于我的项目的结构,我使用代理同时托管了后端和前端。当我在本地主机上运行我的应用程序时,一切正常,我的响应路由也正常工作,因此我知道这与我的代码无关。我已经检查了我的日志,并且我的请求到达了正确的端点,但是,由于403、500和404的缘故,我的前端都没有渲染。我已经将其指向我的web.config文件,但我不知道它应该是什么样子。有关我要呈现哪个文件的一些信息,在这里

这里还有github仓库,以防万一 https://github.com/ecoulson/OverlakeASB

index.html的路径:/client/public/index.html

前端的路径:/ client

这是我的package.json

{
  "name": "overlakeasb",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node server.js 3001",
    "heroku-postbuild": "cd client && npm install && npm run build",
    "postinstall": "cd client && npm install && npm run build"
  },
  "engines": {
    "node": "8.11.1",
    "npm": "5.6.0"
  },
  "dependencies": {
    "@fortawesome/fontawesome-svg-core": "^1.2.0-14",
    "@fortawesome/free-brands-svg-icons": "^5.1.0-11",
    "@fortawesome/free-regular-svg-icons": "^5.1.0-11",
    "@fortawesome/free-solid-svg-icons": "^5.2.0",
    "@fortawesome/react-fontawesome": "0.1.0-11",
    "azure-keyvault": "^3.0.4",
    "cookie-parser": "~1.4.3",
    "debug": "~2.6.9",
    "easy-rbac": "^3.1.0",
    "easy-session": "^2.0.1",
    "express": "~4.16.0",
    "express-session": "^1.15.6",
    "http-errors": "~1.6.2",
    "i": "^0.3.6",
    "jade": "~1.11.0",
    "jquery": "^3.3.1",
    "moment": "^2.22.2",
    "morgan": "~1.9.0",
    "mssql-connection-string": "^0.1.0",
    "mysql": "github:mysqljs/mysql",
    "node-fetch": "^2.2.0",
    "npm": "^6.2.0",
    "q": "^1.5.1",
    "rc-dropdown": "^2.2.0",
    "rc-menu": "^7.2.6",
    "react": "^16.4.2",
    "react-addons-css-transition-group": "^15.6.2",
    "react-animate-height": "^2.0.3",
    "react-contextmenu": "^2.9.3",
    "react-dom": "^16.4.2",
    "react-router": "^4.3.1",
    "react-router-dom": "^4.3.1",
    "react-router-transition": "^1.2.1",
    "react-select": "^2.0.0",
    "react-tooltip": "^3.6.1",
    "tedious": "^2.6.3",
    "tedious-connection-pool": "^1.0.5"
  }
}

这是到目前为止的我的web.config

<configuration>
    <system.webServer>
        <webSocket enabled="false" />
        <handlers>
            <!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
            <add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
        </handlers>
        <defaultDocument enabled="true">
            <files>
                <add value="/client/public/index.html" />
            </files>
        </defaultDocument>
        <rewrite>
            <rules>
                <rule name="React Routes" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="/client/public/index.html" />
                </rule>
            </rules>
        </rewrite>
        <tracing> 
            <traceFailedRequests> 
                <add path="*"> 
                    <traceAreas> 
                        <add provider="WWW Server" areas="Security" verbosity="Verbose" /> 
                    </traceAreas> 
                    <failureDefinitions statusCodes="404.2" /> 
                </add> 
            </traceFailedRequests> 
        </tracing> 
    </system.webServer>
    <system.applicationHost>
        <traceFailedRequestsLogging  enabled="true" /> 
    </system.applicationHost>
</configuration>

1 个答案:

答案 0 :(得分:1)

您可以尝试添加

<globalModules>
<add name="iisnode" image="<path-to-iisnode.dll>" />
</globalModules>