【问题标题】:GAE executing GET request twiceGAE 两次执行 GET 请求
【发布时间】:2021-09-28 12:26:37
【问题描述】:

我是 GAE 的新手,面临执行请求两次的问题。以下是我的简单要求。

const express = require("express");
var app = new express();
app.use(express.json());

app.get("/", (req, res) => {
  setTimeout(() => {
    res.json({ finalResponse: 1 });
  }, 5000);
});

const PORT = process.env.PORT || 8000;
app.listen(PORT, () => {
  console.log(`Server listening on port ${PORT}...`);
});

当我执行请求时,我在网络选项卡中看到 2 个请求,这是因为内部重定向

我的 app.yaml 如下所示

runtime: nodejs14
env: standard
service: server-api
instance_class: F4_1G
handlers:
  - url: /.*
    script: auto
    secure: always
    redirect_http_response_code: 301

需要进行哪些配置更改才能避免 307 重定向并默认强制执行 https

【问题讨论】:

    标签: node.js google-app-engine


    【解决方案1】:

    我认为这是无法避免的。从浏览器的角度考虑它。 http 请求确实被重定向到 https,并且地址栏中的 URL 发生变化。这是期望的行为,并且 307 告诉用户发生了什么。用户最终看到的响应来自https 请求

    【讨论】:

    • 我实际上只传递了 https 请求,但我不知道为什么它首先以 http 形式出现,然后在内部被重定向到 https。我会尝试准备一段视频来展示演示。
    • 您已用红线对图片中的网址进行了编辑,但看起来您首先访问了http:// 网址。
    • 我刚刚观察到这仅在 chrome 中发生。我自己发出 https 请求,但不知道为什么 chrome 有时会先发送一个 http 请求,并且在中途被取消。在 chrome 中从 hsts 中删除域可以解决问题。
    猜你喜欢
    • 2013-03-08
    • 2020-04-20
    • 2014-09-19
    • 1970-01-01
    • 2015-05-16
    • 2021-06-01
    • 2019-12-11
    • 1970-01-01
    • 2014-11-26
    相关资源
    最近更新 更多