1
votes

I'm trying ti deploy a NodeJS App to Azure. Everything works fine including react. but when I'm trying to hit the GraphQL server I'm getting a 404 Error

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Any Ideas?

Here is my 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')
})
1

1 Answers

0
votes

Judging by this document https://babeljs.io/docs/usage/require/ it appears that tooling for ES6 only happens via the next requires

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

So you'll need something like this instead:

// 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')
})