On the development side of my application I can connect to the remote MongoDB database. Currently I am stuck at how to properly configure for deployment on my remote server.`
To my best abilities I have narrowed it down to two locations that are my issues. Apollo if faulting when on my hosting service searching for “Best AI Website Builders - My Website - [Free Trial] - AI Website Builders Reviewed - Best 3 AI Website Builders - Create Website With Ai”`
These are some of the errors.
Error: Attempt to postMessage on disconnected port
XHR POST https://mywebsite.net/path/graphql:4000
[HTTP/2 404 Not Found 290ms]
[Network error]: ServerError: Response not successful: Received status code 404
BOOKS_QUERY error ApolloError: Response not successful: Received status code 404
This is the content of index.js used to setup the server connection.`
import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';
import { resolvers } from "./resolvers.js";
import {typeDefs} from './typeDefs.js';
import mongoose from "mongoose";
mongoose.set('strictQuery', true);
const db = await mongoose.connect("mongodb+srv://MYUSERNAME:MYPASSWORD@MYURL.oqfyjzw.mongodb.net/MYDATABSE?retryWrites=true&w=majority", {
useNewUrlParser: true,
})
console.info ('Connected to db', db?.connections[0]?._connectionString);
const server = new ApolloServer({typeDefs, resolvers});
const { url } = await startStandaloneServer(server, {
listen: { port: 4000 },
});
console.info(` Server ready at ${url}`);
Bellow is the portion used for connection on the client side within App.js .
import React from "react";
import { ApolloClient, InMemoryCache, ApolloProvider, HttpLink, from } from '@apollo/client';
import { onError } from "@apollo/client/link/error";
const errorLink = onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors)
graphQLErrors.forEach(({ message, locations, path }) =>
console.log(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
)
);
if (networkError) console.log(`[Network error]: ${networkError}`);
});
//const httpLink = new HttpLink({ uri: 'http://localhost:4000' });
const httpLink = new HttpLink({ uri: './graphql:4000' });
const client = new ApolloClient({
cache: new InMemoryCache(),
link: from([errorLink, httpLink]),
});
....