为 hapijs 17.2 中的所有路由添加 cors 支持

adding cors support to all the routes in hapijs 17.2

查看最新 17.2.0 版本的文档,在我看来,我必须明确地为每个路由添加 cors 支持。但是,以下对我不起作用

server.route({
    method: 'GET',
    path: path,
    handler: handler,
    options: {
        cors: true
    }
});

而且,即使这样做了,我真的很想在一个地方为所有路由添加 cors 支持,而不是分别为每条路由添加支持。在以前的版本中,我可以执行以下操作

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

但这似乎不再可能了。我该怎么办?

在 hapijs 17 中,您使用服务器构造函数初始化连接详细信息。 server.connection() 不再可用。

const server = new Hapi.Server({  
  host: 'localhost',
  port: 3000,
  routes: {cors: true}
})

Source: hapijs API