[英]Express.js POST returns 404 on IIS
I have an express server that I am hosting using IIS. 我有一个使用IIS托管的快速服务器。 I'm having an issue where my POST requests all return 404 pages.
我遇到一个问题,我的POST请求全部返回404页。 My GET requests work fine.
我的GET请求工作正常。
Here is my server.js
这是我的
server.js
const express = require('express');
const cors = require('cors');
const puppeteer = require('puppeteer');
const { createUrl } = require('./urlBuilder');
const app = express();
app.use(express.json());
app.use(cors());
const pdfConfig = {
format: 'A4',
printBackground: true,
margin: {
top: '1cm',
bottom: '1cm',
left: '1.5cm',
right: '1.5cm'
}
};
// Our first route
app.get('/test', function (req, res) {
res.send('Hello Dev!');
});
app.post('/create-pdf', function(req, res) {
const url = createUrl(req.body);
const browser = puppeteer.launch();
browser.then((brw) => {
const page = brw.newPage();
page.then((pg) => {
pg.goto(url).then(() => {
pg.emulateMedia('screen').then(() => {
const buffer = pg.pdf(pdfConfig);
buffer.then((buf) => {
brw.close();
res.end(buf.toString('base64'));
})
})
})
})
});
});
Here is my web.config
这是我的
web.config
<configuration>
<system.webServer>
<!-- indicates that the server.js file is a node.js application
to be handled by the iisnode module -->
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="sendToNode">
<match url="/*" />
<action type="Rewrite" url="server.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
If I use a REST client like insomnia and GET http://example.com/test it works fine but POST to http://example.com/create-pdf returns a 404. Am I missing anything here? 如果我使用失眠症和GET http://example.com/test之类的REST客户端,它可以正常工作,但是POST到http://example.com/create-pdf会返回404。我在这里丢失了什么吗?
The default request method for rewrite/redirects is always GET. 重写/重定向的默认请求方法始终是GET。 For other verb rewrites they need to be explicitly added.
对于其他动词重写,需要显式添加它们。
Add a new rule exactly like the one you have and add the following condition into the rule: 添加与您拥有的规则完全相同的新规则,并将以下条件添加到规则中:
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" />
</conditions>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.