Nodejs Hapi-如何启用跨源访问控制 [英] Nodejs Hapi - How to enable cross origin access control

查看:93
本文介绍了Nodejs Hapi-如何启用跨源访问控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用HapiJs Restful Web服务,并尝试启用cors,以便任何来自不同域的客户端都可以使用我的服务.我在服务器连接对象中尝试了cors = true,但是没有用.

I am working HapiJs Restful web service and trying to enable cors so any client even from different domain can consume my services. I tried cors=true in server connection object but didn't work.

推荐答案

您将cors=true放在哪里?您可以添加一些代码吗?

Where did you put cors=true? Could you add some code?

在不知道确切地放置cors = true的位置的情况下,这段代码可能会帮助您:

Without know exactly where you've put cors = true, this bit of code may help you:

server.connection({ routes: { cors: true } })

或者尝试在路由的config部分中添加允许的cors.

Or try adding the allowed cors in the config section of your route.

server.route({
    config: {
        cors: {
            origin: ['*'],
            additionalHeaders: ['cache-control', 'x-requested-with']
        }
    },

看看这个问题: 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆