首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在我的Graphql服务器中添加cors (Typescript)

如何在我的Graphql服务器中添加cors (Typescript)
EN

Stack Overflow用户
提问于 2018-02-09 09:24:31
回答 1查看 117关注 0票数 0

我在我的graphql服务器上应用cors时遇到了一个问题,因为它不起作用,我研究了很多,但所有这些都不起作用。

代码如下:

代码语言:javascript
复制
import { BasicServer } from 'realm-object-server'
import * as path from 'path'
import { GraphQLService } from 'realm-graphql-service'`enter code here`
import {cors} from 'cors'

const server = new BasicServer()

server.addService(new GraphQLService({
    // Turn this off in production!
    disableAuthentication: true
}))

server.start({
        // This is the location where ROS will store its runtime data
        dataPath: path.join(__dirname, '../data'),
        middlewares: [cors()]

    })
    .then(() => {
        console.log(`Realm Object Server was started on ${server.address}`)
    })
    .catch(err => {
        console.error(`Error starting Realm Object Server: ${err.message}`)
    })

如何在此graphql服务器上成功应用cors?

EN

回答 1

Stack Overflow用户

发布于 2018-02-09 09:46:34

我觉得你导入cors的方式不对,试试这个:

代码语言:javascript
复制
import { BasicServer } from 'realm-object-server'
import * as path from 'path'
import { GraphQLService } from 'realm-graphql-service'`enter code here`
import * as cors from 'cors' // <====

const server = new BasicServer()

server.addService(new GraphQLService({
    // Turn this off in production!
    disableAuthentication: true
}))

server.start({
        // This is the location where ROS will store its runtime data
        dataPath: path.join(__dirname, '../data'),
        middlewares: [cors()]

    })
    .then(() => {
        console.log(`Realm Object Server was started on ${server.address}`)
    })
    .catch(err => {
        console.error(`Error starting Realm Object Server: ${err.message}`)
    })

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48697389

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档