我的后端是一个NodeJS服务器,具有以下CORS配置:
app.use(cors({
origin: ['https://example.com, 'https://destination.com'],
allowedHeaders: ['Origin','Accept','X-Requested-With','Content-Type']
}));
当NodeJS后端发送302 Found响应时,IIS会替换位置;将重定向到destination.com/endpoint?p=v更改为example.com/endpoint?p=v。以下是来自IIS“失败请求跟踪”的日志:
135. NOTIFY_MODULE_START ModuleName="ApplicationRequestRouting", Notification="EXECUTE_REQUEST_HANDLER", fIsPostNotification="false" 01:16:27.109
136. ARR_REQUEST_HEADERS_START 01:16:27.109
137. ARR_REQUEST_HEADERS_END 01:16:27.125
138. ARR_RESPONSE_HEADERS_START 01:16:27.125
139. ARR_RESPONSE_HEADERS_END 01:16:27.125
140. MODULE_SET_RESPONSE_SUCCESS_STATUS ModuleName="ApplicationRequestRouting", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="302", HttpReason="Found" 01:16:27.125
141. GENERAL_SET_RESPONSE_HEADER HeaderName="Content-Length", HeaderValue="0", Replace="true" 01:16:27.125
142. GENERAL_SET_RESPONSE_HEADER HeaderName="Location", HeaderValue="https://destination.com/foo/bar?p=v", Replace="true" 01:16:27.125
143. GENERAL_SET_RESPONSE_HEADER HeaderName="Vary", HeaderValue="Origin", Replace="true" 01:16:27.125
144. GENERAL_SET_RESPONSE_HEADER HeaderName="X-Powered-By", HeaderValue="Express", Replace="false" 01:16:27.125
145. GENERAL_SET_RESPONSE_HEADER HeaderName="Location", HeaderValue="https://example.com/foo/bar?p=v", Replace="true" 01:16:27.125
146. GENERAL_SET_RESPONSE_HEADER HeaderName="X-Powered-By", HeaderValue="ARR/3.0", Replace="false" 01:16:27.125
147. NOTIFY_MODULE_END ModuleName="ApplicationRequestRouting", Notification="EXECUTE_REQUEST_HANDLER", fIsPostNotificationEvent="false", NotificationStatus="1" 01:16:27.125
148. NOTIFY_MODULE_COMPLETION ModuleName="ApplicationRequestRouting", Notification="EXECUTE_REQUEST_HANDLER", fIsPostNotificationEvent="false", CompletionBytes="0", ErrorCode="The operation completed successfully.
(0x0)" 01:16:27.125
149. ARR_RESPONSE_ENTITY_START 01:16:27.125
150. ARR_RESPONSE_ENTITY_END Bytes="0" 01:16:27.125
151. NOTIFY_MODULE_END ModuleName="ApplicationRequestRouting", Notification="EXECUTE_REQUEST_HANDLER", fIsPostNotificationEvent="false", NotificationStatus="1" 01:16:27.125
152. NOTIFY_MODULE_COMPLETION ModuleName="ApplicationRequestRouting", Notification="EXECUTE_REQUEST_HANDLER", fIsPostNotificationEvent="false", CompletionBytes="0", ErrorCode="The operation completed successfully.
(0x0)" 01:16:27.125
153. NOTIFY_MODULE_END ModuleName="ApplicationRequestRouting", Notification="EXECUTE_REQUEST_HANDLER", fIsPostNotificationEvent="false", NotificationStatus="NOTIFICATION_CONTINUE"
以下是现有的重写规则:
<rules>
<clear />
<rule name="Upgrade" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{REQUEST_METHOD}" pattern="POST" negate="true" />
<add input="{REQUEST_METHOD}" pattern="FOUND" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" />
</rule>
<rule name="Backend" stopProcessing="true">
<match url="backend/(.*)" />
<action type="Rewrite" url="http://localhost:3001/{R:1}" />
</rule>
<rule name="React Router" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_URI}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.html" />
</rule>
</rules>
没有其他ARR模块具有适当的规则。
是否需要为CORS配置IIS?谢谢
1条答案
按热度按时间brvekthn1#
转到服务器的IIS“主页”页,打开“应用程序请求路由缓存”。在服务器代理设置中有一个选项,标记为“在响应报头中反向重写主机”。取消选中该选项解决了我的问题。