I deployed my Express API to Railway and its talking to Redis and Postgres nicely. My client is built in Next 13 with the App Router and is having trouble discovering blackjack.railway.internal:8080
I think this has to do with my binding the Express app to an IPv6 port or at least making it accessible through IPv6 however after a few hours of searching I'm unable to find a clear way of doing this?
client <> server is communicating through ApolloServer.
logger.warn(`Launching in ${process.env.NODE_ENV.toUpperCase()}`);
const schema = makeExecutableSchema({
typeDefs,
resolvers: {
Query,
Mutation,
Subscription,
},
});
const limiter = rateLimit({
windowMs: 1 * 60 * 1000, // 1 minute
max: 20,
});
// Create an Express app and HTTP server; attach both the WebSocket
// server and the ApolloServer to this HTTP server.
const app = express();
const httpServer = createServer(app);
// Create WebSocket server using the HTTP server we just set up.
const wsServer = new WebSocketServer({
server: httpServer,
path: '/graphql',
});
// Save returned server's info so we can shutdown this server later
const wsServerCleanup = useServer(
{
schema,
context: async (ctx, msg, args) => {
return { pubsub };
},
},
wsServer
);
// Create ApolloServer.
const server = new ApolloServer({
schema,
// just added could cause errors
csrfPrevention: true,
plugins: [
// Proper shutdown for the HTTP server.
ApolloServerPluginDrainHttpServer({ httpServer }),
// Proper shutdown for the WebSocket server.
{
async serverWillStart() {
return {
async drainServer() {
await wsServerCleanup.dispose();
},
};
},
},
],
});
const main = async () => {
// Apollo/GraphQL server start.
await server.start();
if (server) {
logger.info(
`Apollo/GraphQL API is now live on endpoint: ${NODE_PORT}/graphql`
);
} else {
logger.fatal(`Could not start Apollo/GraphQL API`);
process.exit(1);
}
// Middleware for the express application.
app.use(
'/graphql',
cors(),
helmet(),
limiter,
bodyParser.json(),
expressMiddleware(server, {
context: async ({ req }) => {
return { prisma, pubsub, req };
},
})
);
app.get('/health', (req, res) => {
res.status(200).send('Okay!');
});
const hostname = '::';
// http server start
httpServer.listen(NODE_PORT, hostname, () => {
logger.info(
`Apollo/GraphQL websocket service is live on endpoint: ${NODE_PORT}/graphql`
);
});
setTimeout(() => {
pingRedis();
}, 1000);
};
main();
This is my app.js in my server root. Thanks for any insights.