我正在尝试在 Azure WebApp 上托管一个简单的 Nextjs 应用程序,我尝试按照几个在线教程来配置它,但没有一个能够帮助我。
我正在使用 Nextjs 的 SSR 配置,并且只创建了两个组件来在 Azure 托管上测试它。
现在我陷入了 Node 的服务器配置,我尝试放置一个我在示例中看到的 web.config 文件,但似乎我的请求没有到达应用程序服务器。
这是我的 web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <webSocket enabled="false" />
        <handlers>
            <add name="iisnode" path="app/server.js" verb="*" modules="iisnode"/>
        </handlers>
        <rewrite>
            <rules>
                <rule name="API">
                    <match url="^api(.*)$" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{SCRIPT_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                        <add input="{SCRIPT_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="api/index.php" appendQueryString="true" />
                </rule>
                <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url="^app/server.js\/debug[\/]?" />
                </rule>
                <rule name="StaticContent">
                    <action type="Rewrite" url="public{REQUEST_URI}"/>
                </rule>
                <rule name="DynamicContent">
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
                    </conditions>
                    <action type="Rewrite" url="app/server.js"/>
                </rule>
            </rules>
        </rewrite>
        <security>
            <requestFiltering>
                <hiddenSegments>
                    <remove segment="bin"/>
                </hiddenSegments>
            </requestFiltering>
        </security>
        <httpErrors existingResponse="PassThrough" />
    </system.webServer>
</configuration> 
这是我的 server.js
const express = require('express')
const next = require('next')
const nextConfig = require('../next.config')
const port = process.env.PORT || 8080
const dev = process.env.NODE_ENV !== 'production'
const app = next({
    dev: dev,
    dir: './app',
    conf: nextConfig
})
const handle = app.getRequestHandler()
app.prepare().then(() => {
    const server = express()
    server.get('/home', (req, res) => {
        return app.render(req, res, '/home', req.query)
    })
    server.get('*', (req, res) => {
        return handle(req, res)
    })
    server.listen(port, err => {
        if (err) throw err
            console.log(`> Ready on http://localhost:${port}`)
    })
})
| 归档时间: | 
 | 
| 查看次数: | 727 次 | 
| 最近记录: |