Use Fastify Mercurius and GraphQL contracts
Some checks are pending
Build Docker Image / build (push) Waiting to run
Some checks are pending
Build Docker Image / build (push) Waiting to run
This commit is contained in:
35
src/index.ts
35
src/index.ts
@@ -1,22 +1,21 @@
|
||||
import express from 'express'
|
||||
import cors from 'cors'
|
||||
import { ApolloServer } from '@apollo/server'
|
||||
import { expressMiddleware } from '@apollo/server/express4'
|
||||
import { typeDefs, resolvers } from './schema.js'
|
||||
import Fastify from "fastify";
|
||||
import cors from "@fastify/cors";
|
||||
import mercurius from "mercurius";
|
||||
import { typeDefs, resolvers } from "./schema.js";
|
||||
|
||||
const PORT = parseInt(process.env.PORT || '8000', 10)
|
||||
const PORT = Number.parseInt(process.env.PORT || "8000", 10);
|
||||
|
||||
const app = express()
|
||||
app.use(cors({ origin: ['https://optovia.ru'], credentials: true }))
|
||||
const app = Fastify();
|
||||
await app.register(cors, { origin: ["https://optovia.ru"], credentials: true });
|
||||
await app.register(mercurius, {
|
||||
schema: typeDefs,
|
||||
resolvers,
|
||||
path: "/graphql/public",
|
||||
graphiql: true,
|
||||
});
|
||||
|
||||
const server = new ApolloServer({ typeDefs, resolvers, introspection: true })
|
||||
await server.start()
|
||||
app.get("/health", async () => ({ status: "ok" }));
|
||||
|
||||
app.use('/graphql/public', express.json(), expressMiddleware(server) as unknown as express.RequestHandler)
|
||||
|
||||
app.get('/health', (_, res) => { res.json({ status: 'ok' }) })
|
||||
|
||||
app.listen(PORT, '0.0.0.0', () => {
|
||||
console.log(`Geo server ready on port ${PORT}`)
|
||||
console.log(` /graphql/public - public (no auth)`)
|
||||
})
|
||||
await app.listen({ port: PORT, host: "0.0.0.0" });
|
||||
console.log(`Geo server ready on port ${PORT}`);
|
||||
console.log(` /graphql/public - public (no auth)`);
|
||||
|
||||
Reference in New Issue
Block a user