0

I have been scratching my head now for 2 whole days on this :D I thought initially it was the reverse proxy. However that was folly as of course, this could not be the case as the /graphiql endpoint was working perfectly. Just with no scheme loaded.

So now, I just cannot work out why the /graphql endpoint would hang indefinitely. I can only think that it's possible I don't have access to the psql db? However I have tested that the /graphql endpoint is accessable via:

// Works as expected and returns results correctly 
curl -H 'Content-Type: application/json' -X POST -d '<json>'  -H "Host: https://<https_url>.com" http://127.0.0.1:4006/graphql

Which is even more confusing...

server.js

import cors from 'cors'

import scrape from './src/api/routes/scrape'

const express = require('express')
const { ApolloServer, gql } = require('apollo-server-express')
const { postgraphile } = require('postgraphile')
const ConnectionFilterPlugin = require('postgraphile-plugin-connection-filter')

const dbHost = process.env.DB_HOST
const dbPort = process.env.DB_PORT
const dbName = process.env.DB_NAME
const dbUser = process.env.DB_USER
const dbPwd = process.env.DB_PWD
const dbUrl = dbPwd
  ? `postgres://${dbUser}:${dbPwd}@${dbHost}:${dbPort}/${dbName}`
  : `postgres://${dbHost}:${dbPort}/${dbName}`

var corsOptions = {
  origin: '*',
  optionsSuccessStatus: 200, // some legacy browsers (IE11, various SmartTVs) choke on 204
}

async function main() {
  // Construct a schema, using GraphQL schema language
  const typeDefs = gql`
    type Query {
      hello: String
    }
  `

  // Provide resolver functions for your schema fields
  const resolvers = {
    Query: {
      hello: () => 'Hello world!',
    },
  }

  const server = new ApolloServer({ typeDefs, resolvers })

  const app = express()
  app.use(cors(corsOptions))
  app.use(
    postgraphile(process.env.DATABASE_URL || dbUrl, 'public', {
      appendPlugins: [ConnectionFilterPlugin],
      watchPg: true,
      graphiql: true,
      enhanceGraphiql: true,
    })
  )
  server.applyMiddleware({ app })

  //Scraping Tools
  scrape(app)

  const port = 4006
  await app.listen({ port })
  console.log(` Server ready at http://localhost:${port}`)
}

main().catch(e => {
  console.error(e)
  process.exit(1)
})

Just for brevity's sake here is the vhost:

<VirtualHost 185.132.41.127:80>
    ServerName api.miniatureawards.com
    Redirect permanent / https://api.miniatureawards.com/
</VirtualHost>
<IfModule mod_ssl.c>
    <VirtualHost 185.132.41.127:443>
        ServerAdmin jamie@hutber.com
        ServerName api.miniatureawards.com

        ProxyRequests on
        LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
        LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so

        ProxyPass / http://localhost:4006/
        ProxyPassReverse / http://localhost:4006/
    

        #certificates SSL
        SSLEngine on

        ErrorLog ${APACHE_LOG_DIR}/error_api.miniatureawards.com.log
        CustomLog ${APACHE_LOG_DIR}/access_api.miniatureawards.com.log combined

    </VirtualHost>
</IfModule>
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Jamie Hutber
  • 26,790
  • 46
  • 179
  • 291
  • Debug: Is there a network connection to the database? Is there a database session? What is its state? And so on. – Laurenz Albe Oct 21 '21 at 02:50
  • Thanks @LaurenzAlbe Well its very difficult to confirm if there is a successful connection to psql at this point. My psql logs are empty. As is the error log for api.miniatures. psql is active. Apache is too. This is the url https://api.miniatureawards.com/graphiql that would be trying to connect to psql via `\graphql`. `process.env.DATABASE_URL || dbUrl` is the line of code that will do the connecting for me. – Jamie Hutber Oct 21 '21 at 10:20
  • If there is no PostgreSQL log message even when you set `log_connections = on`, you don't even reach the PostgreSQL server. – Laurenz Albe Oct 21 '21 at 10:39
  • Thanks again! So this is a step for me :D At least I know that it isn't _yet_ an issue with auth. I cannot think for a single reason why my FE cannot access psql. It work locally and I see now errors yet. – Jamie Hutber Oct 21 '21 at 10:53
  • Possibly this is important information on my postgraphile setup: database Url = `postgres://username:password@localhost:5432/miniatureawards` I am wondering if I need to point anything at localhost:4006? – Jamie Hutber Oct 21 '21 at 12:03
  • That looks correct. – Laurenz Albe Oct 21 '21 at 13:22
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/238400/discussion-between-jamie-hutber-and-laurenz-albe). – Jamie Hutber Oct 21 '21 at 14:01
  • I notice you have both Apollo Server and Posgraphile enabled. Have you tried commenting out either the ApolloServer or Postgraphile block and seeing if it works? My guess is that there is a conflict as both would use the /graphql endpoint. – THX1138 Apr 13 '22 at 19:42

0 Answers0