0

我已经为此挠头整整两天了:DI最初认为它是反向代理。然而,这当然是愚蠢的,因为/graphiql 端点工作完美,所以情况并非如此。只是没有加载任何方案。

所以现在,我无法弄清楚为什么/graphql端点会无限期地挂起。我只能认为我可能无权访问 psql db?但是我已经测试过/graphql端点可以通过以下方式访问:

// 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

哪个更令人困惑...

服务器.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)
})

为简洁起见,这里是虚拟主机:

<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>
4

0 回答 0