gpt4 book ai didi

node.js - Azure 服务器上的 GraphQL

转载 作者:行者123 更新时间:2023-12-03 04:28:13 28 4
gpt4 key购买 nike

我正在尝试将 NodeJS 应用程序部署到 Azure。一切正常,包括 react 。但是当我尝试访问 GraphQL 服务器时,我收到了 404 错误

您正在查找的资源已被删除、更名或暂时不可用。

有什么想法吗?

这是我的index.js

'use strict'
require('babel-core/register')
import schema from './data/schema'
import GraphQLHTTP from 'express-graphql'
import express from 'express'
const multer = require('multer')
const insert = require('./business/insert')
const app = express()
const port = process.env.PORT || 8080
var bodyParser = require('body-parser')

app.use(bodyParser.json()) // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })) // support encoded bodies
app.use('/graphql', GraphQLHTTP({
schema,
graphiql: true
}))

app.use(express.static('public'))
app.set('view engine', 'html')

var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, 'public/upload/')
},
filename: function (req, file, cb) {
cb(null, Date.now() + '.xlsx')
}
})

var upload = multer({ storage: storage })

app.get('/', (req, res) => {
res.render('index')
})

app.listen(port, () => {
console.log('Listening http://localhost:8080')
})

最佳答案

根据本文档判断https://babeljs.io/docs/usage/require/看来 ES6 的工具只能通过下一个 requires

来实现

All subsequent files required by node with the extensions .es6, .es, .jsx and .js will be transformed by Babel.

所以你需要这样的东西:

// app.js
'use strict'
require('babel-core/register')
require('./index')

// index.js
import schema from './data/schema'
import GraphQLHTTP from 'express-graphql'
import express from 'express'
const multer = require('multer')
const insert = require('./business/insert')
const app = express()
const port = process.env.PORT || 8080
var bodyParser = require('body-parser')

app.use(bodyParser.json()) // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })) // support encoded bodies
app.use('/graphql', GraphQLHTTP({
schema,
graphiql: true
}))

app.use(express.static('public'))
app.set('view engine', 'html')

var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, 'public/upload/')
},
filename: function (req, file, cb) {
cb(null, Date.now() + '.xlsx')
}
})

var upload = multer({ storage: storage })

app.get('/', (req, res) => {
res.render('index')
})

app.listen(port, () => {
console.log('Listening http://localhost:8080')
})

关于node.js - Azure 服务器上的 GraphQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40471156/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com