我在我的graphql服务器上应用cors时遇到了一个问题,因为它不起作用,我研究了很多,但所有这些都不起作用。
代码如下:
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?
发布于 2018-02-09 09:46:34
我觉得你导入cors的方式不对,试试这个:
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}`)
})
https://stackoverflow.com/questions/48697389
复制相似问题