<tfoot id='t43qn'></tfoot>

      <bdo id='t43qn'></bdo><ul id='t43qn'></ul>

    <small id='t43qn'></small><noframes id='t43qn'>

  1. <legend id='t43qn'><style id='t43qn'><dir id='t43qn'><q id='t43qn'></q></dir></style></legend>

      <i id='t43qn'><tr id='t43qn'><dt id='t43qn'><q id='t43qn'><span id='t43qn'><b id='t43qn'><form id='t43qn'><ins id='t43qn'></ins><ul id='t43qn'></ul><sub id='t43qn'></sub></form><legend id='t43qn'></legend><bdo id='t43qn'><pre id='t43qn'><center id='t43qn'></center></pre></bdo></b><th id='t43qn'></th></span></q></dt></tr></i><div id='t43qn'><tfoot id='t43qn'></tfoot><dl id='t43qn'><fieldset id='t43qn'></fieldset></dl></div>

      在 express js 中允许多个 CORS 域

      时间:2023-09-03

        <legend id='t4KDI'><style id='t4KDI'><dir id='t4KDI'><q id='t4KDI'></q></dir></style></legend>

          <tbody id='t4KDI'></tbody>
        <tfoot id='t4KDI'></tfoot>
        • <bdo id='t4KDI'></bdo><ul id='t4KDI'></ul>
          1. <i id='t4KDI'><tr id='t4KDI'><dt id='t4KDI'><q id='t4KDI'><span id='t4KDI'><b id='t4KDI'><form id='t4KDI'><ins id='t4KDI'></ins><ul id='t4KDI'></ul><sub id='t4KDI'></sub></form><legend id='t4KDI'></legend><bdo id='t4KDI'><pre id='t4KDI'><center id='t4KDI'></center></pre></bdo></b><th id='t4KDI'></th></span></q></dt></tr></i><div id='t4KDI'><tfoot id='t4KDI'></tfoot><dl id='t4KDI'><fieldset id='t4KDI'></fieldset></dl></div>

              <small id='t4KDI'></small><noframes id='t4KDI'>

              • 本文介绍了在 express js 中允许多个 CORS 域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                如何以简化的方式允许 CORS 使用多个域.

                How do I allow multiple domains for CORS in express in a simplified way.

                我有

                 cors: {
                        origin: "www.one.com";
                    }
                
                    app.all('*', function(req, res, next) {
                            res.header("Access-Control-Allow-Origin", cors.origin);
                            res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
                            next();
                        });
                

                这在 origin

                但是,如果我想将 origin 作为域数组,并且我想允许原始数组中的所有域使用 CORS,我就会有这样的东西 -

                But if I want to have origin as an array of domains and I want to allow CORS for all the domains in the origin array, I would have something like this -

                cors: {
                            origin: ["www.one.com","www.two.com","www.three.com"];
                        }
                

                但问题是下面的代码不起作用 -

                But then the problem is this below code would not work -

                app.all('*', function(req, res, next) {
                                res.header("Access-Control-Allow-Origin", cors.origin);
                                res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
                                next();
                            });
                

                如何让 res.header 通过 cors.origin 获取一个域数组?

                How do I make res.header take an array of domains via cors.origin ?

                推荐答案

                我会推荐 cors-module: https://www.npmjs.org/package/cors它为您做这种事情 - 检查配置 CORS w/动态原点"-Section

                I would recommend the cors-module: https://www.npmjs.org/package/cors It does this kind of stuff for you - check the "Configuring CORS w/ Dynamic Origin"-Section

                这篇关于在 express js 中允许多个 CORS 域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:跨域请求被阻止:同源策略不允许读取远程资源 下一篇:跨域资源共享 (CORS) 是否区分 HTTP 和 HTTPS?

                相关文章

                最新文章

                  <bdo id='7A1wD'></bdo><ul id='7A1wD'></ul>
              • <i id='7A1wD'><tr id='7A1wD'><dt id='7A1wD'><q id='7A1wD'><span id='7A1wD'><b id='7A1wD'><form id='7A1wD'><ins id='7A1wD'></ins><ul id='7A1wD'></ul><sub id='7A1wD'></sub></form><legend id='7A1wD'></legend><bdo id='7A1wD'><pre id='7A1wD'><center id='7A1wD'></center></pre></bdo></b><th id='7A1wD'></th></span></q></dt></tr></i><div id='7A1wD'><tfoot id='7A1wD'></tfoot><dl id='7A1wD'><fieldset id='7A1wD'></fieldset></dl></div>

                  <tfoot id='7A1wD'></tfoot>
                1. <legend id='7A1wD'><style id='7A1wD'><dir id='7A1wD'><q id='7A1wD'></q></dir></style></legend>

                  1. <small id='7A1wD'></small><noframes id='7A1wD'>