Angular代理.NET核心后端每隔时间工作

发布于 2025-01-24 19:01:50 字数 1319 浏览 2 评论 0原文

遇到一些怪异的东西..试图从我的Angular应用中击中我的API。由于我们需要使用Windows身份验证,因此我们需要为Angular设置代理。Conf,以便它可以正确传递凭据。 这是我的proxy.conf.js:

    const agent = require('agentkeepalive');

    module.exports = {
        '/api': {
            target: 'http://localhost:44366',
            secure: false,
            agent: new agent({
                maxSockets: 100,
                keepAlive: true,
                maxFreeSockets: 10,
                keepAliveMsecs: 100000,
                timeout: 6000000,
                keepAliveTimeout: 90000,
            }),
            onProxyRes: proxyRes => {
                let key = 'www-authenticate';
                proxyRes.headers[key] = proxyRes.headers[key] && proxyRes.headers[key].split(',');
            },
        },
    };

在其他所有请求中获取这些错误:

如果没有失败,我的第一个请求就成功了,但以下请求每次都会失败502。

Running into some weird stuff.. Trying to hit my api from my angular app. Since We need to use windows authentication we need to setup a proxy.conf for angular so it can pass credentials correctly.
Here is my proxy.conf.js:

    const agent = require('agentkeepalive');

    module.exports = {
        '/api': {
            target: 'http://localhost:44366',
            secure: false,
            agent: new agent({
                maxSockets: 100,
                keepAlive: true,
                maxFreeSockets: 10,
                keepAliveMsecs: 100000,
                timeout: 6000000,
                keepAliveTimeout: 90000,
            }),
            onProxyRes: proxyRes => {
                let key = 'www-authenticate';
                proxyRes.headers[key] = proxyRes.headers[key] && proxyRes.headers[key].split(',');
            },
        },
    };

Getting these errors every other request:
enter image description here

Without fail my first request succeeds but the following request fails with 502 every time.
enter image description here

enter image description here

Has anyone ever seen something like this before?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吻泪 2025-01-31 19:01:50
const { env } = require('process');
const HttpsAgent = require('agentkeepalive').HttpsAgent;

const target = env.ASPNETCORE_HTTPS_PORT ? `https://localhost:${env.ASPNETCORE_HTTPS_PORT}` :
  env.ASPNETCORE_URLS ? env.ASPNETCORE_URLS.split(';')[0] : 'http://localhost:32101';

  const PROXY_CONFIG = [
    {
      context: ["/api"],
      target: target,
      secure: false,
      changeOrigin: true,
      agent: new HttpsAgent({
        maxSockets: 100,
        keepAlive: true,
        maxFreeSockets: 10,
        keepAliveMsecs: 100000,
        timeout: 6000000,
        freeSocketTimeout: 90000
      }),
      onProxyRes: proxyRes => {
        const key = "www-authenticate";
        proxyRes.headers[key] = proxyRes.headers[key] &&
          proxyRes.headers[key].split(",");
      }
    }
  ]

module.exports = PROXY_CONFIG;

尝试一下,但我对上述端口号不信心 - 您必须为HTTPS和Web API路由设置代理配置,此代码是我的Proxy.conf.js的示例

const { env } = require('process');
const HttpsAgent = require('agentkeepalive').HttpsAgent;

const target = env.ASPNETCORE_HTTPS_PORT ? `https://localhost:${env.ASPNETCORE_HTTPS_PORT}` :
  env.ASPNETCORE_URLS ? env.ASPNETCORE_URLS.split(';')[0] : 'http://localhost:32101';

  const PROXY_CONFIG = [
    {
      context: ["/api"],
      target: target,
      secure: false,
      changeOrigin: true,
      agent: new HttpsAgent({
        maxSockets: 100,
        keepAlive: true,
        maxFreeSockets: 10,
        keepAliveMsecs: 100000,
        timeout: 6000000,
        freeSocketTimeout: 90000
      }),
      onProxyRes: proxyRes => {
        const key = "www-authenticate";
        proxyRes.headers[key] = proxyRes.headers[key] &&
          proxyRes.headers[key].split(",");
      }
    }
  ]

module.exports = PROXY_CONFIG;

try this but im not confident with your port number mentioned above - you have to set proxy configuration for https and routes of web api, this code is example from my proxy.conf.js for new Visual Studio Template

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文