Reactjs 如何在Azure上部署NextJs SSR React应用程序

Reactjs 如何在Azure上部署NextJs SSR React应用程序,reactjs,azure-web-app-service,next.js,azure-pipelines,server-side-rendering,Reactjs,Azure Web App Service,Next.js,Azure Pipelines,Server Side Rendering,我一直在尝试在Azure上部署我用NextJS构建的服务器端应用程序。我设置了Azure管道并成功发布,但运行之后,当我转到Azure网站URL时,应用程序似乎没有加载。生成文件内容与客户端呈现的应用程序不同。请分享有关部署SSR React应用程序(在Azure上)的资源或说明 我曾经设置管道,没有遇到错误,但URL仍然没有加载应用程序。您需要两个文件:server.js和web.config,并修改package.json,如下所示。我已经一步一步地回答了一个关于部署nextjs应用程序的问

我一直在尝试在Azure上部署我用NextJS构建的服务器端应用程序。我设置了Azure管道并成功发布,但运行之后,当我转到Azure网站URL时,应用程序似乎没有加载。生成文件内容与客户端呈现的应用程序不同。请分享有关部署SSR React应用程序(在Azure上)的资源或说明


我曾经设置管道,没有遇到错误,但URL仍然没有加载应用程序。

您需要两个文件:server.jsweb.config,并修改package.json,如下所示。我已经一步一步地回答了一个关于部署nextjs应用程序的问题,您可以看看

package.json修改。

"scripts": {
    "dev": "node server.js",
    "build": "next build",
    "start": "node server.js"
server.js(使用下面的代码创建此文件:)

web.config(使用以下代码创建此文件:)



你可以看看这段视频:@James Doris的回答有帮助吗?如果是这样,你可以,它可以帮助其他社区成员获得同样的问题,谢谢。@EdwardHan MSFT是的,我现在一切都好了。答案worked@EdwardHan-MSFT这是可行的,但应用程序的生产速度非常慢。加载大约需要6-10分钟,从一个页面移动到另一个页面平均需要6秒。请共享一个可能的修复程序。这可以工作,但应用程序的生产速度非常慢。加载大约需要6-10分钟,从一个页面移动到另一个页面平均需要6秒。请分享一个可能的解决方案。
const { createServer } = require('http')
const next = require('next')

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()

app.prepare().then(() => {
  createServer((req, res) => {
    const parsedUrl = new URL(req.url, 'http://w.w')
    const { pathname, query } = parsedUrl

    if (pathname === '/a') {
      app.render(req, res, '/a', query)
    } else if (pathname === '/b') {
      app.render(req, res, '/b', query)
    } else {
      handle(req, res, parsedUrl)
    }
  }).listen(port, (err) => {
    if (err) throw err
    console.log(`> Ready on http://localhost:${port}`)
  })
})
<?xml version="1.0" encoding="utf-8"?>
<!--
     This configuration file is required if iisnode is used to run node processes behind
     IIS or IIS Express.  For more information, visit:
     https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config
-->

<configuration>
  <system.webServer>
    <!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
    <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>
    <rewrite>
      <rules>
        <!-- Do not interfere with requests for node-inspector debugging -->
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^server.js\/debug[\/]?" />
        </rule>

        <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
        <rule name="StaticContent">
          <action type="Rewrite" url="public{REQUEST_URI}"/>
        </rule>

        <!-- All other URLs are mapped to the node.js site entry point -->
        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
          </conditions>
          <action type="Rewrite" url="server.js"/>
        </rule>
      </rules>
    </rewrite>

    <!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
    <security>
      <requestFiltering>
        <hiddenSegments>
          <remove segment="bin"/>
        </hiddenSegments>
      </requestFiltering>
    </security>

    <!-- Make sure error responses are left untouched -->
    <httpErrors existingResponse="PassThrough" />

    <!--
      You can control how Node is hosted within IIS using the following options:
        * watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
        * node_env: will be propagated to node as NODE_ENV environment variable
        * debuggingEnabled - controls whether the built-in debugger is enabled
      See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
    -->
    <!--<iisnode watchedFiles="web.config;*.js"/>-->
  </system.webServer>
</configuration>