All checks were successful
Build Docker Image / build (push) Successful in 2m12s
Replace Python/Django/Graphene with TypeScript/Express/Apollo Server. Same 3 endpoints (public/user/m2m), same JWT auth via Logto. Prisma replaces Django ORM. MongoDB, Temporal and SurrealDB integrations preserved.
81 lines
2.2 KiB
TypeScript
81 lines
2.2 KiB
TypeScript
import express from 'express'
|
|
import cors from 'cors'
|
|
import { ApolloServer } from '@apollo/server'
|
|
import { expressMiddleware } from '@apollo/server/express4'
|
|
import * as Sentry from '@sentry/node'
|
|
import { publicTypeDefs, publicResolvers } from './schemas/public.js'
|
|
import { userTypeDefs, userResolvers } from './schemas/user.js'
|
|
import { m2mTypeDefs, m2mResolvers } from './schemas/m2m.js'
|
|
import { publicContext, userContext, m2mContext, type AuthContext } from './auth.js'
|
|
|
|
const PORT = parseInt(process.env.PORT || '8000', 10)
|
|
const SENTRY_DSN = process.env.SENTRY_DSN || ''
|
|
|
|
if (SENTRY_DSN) {
|
|
Sentry.init({
|
|
dsn: SENTRY_DSN,
|
|
tracesSampleRate: 0.01,
|
|
release: process.env.RELEASE_VERSION || '1.0.0',
|
|
environment: process.env.ENVIRONMENT || 'production',
|
|
})
|
|
}
|
|
|
|
const app = express()
|
|
|
|
app.use(cors({ origin: ['https://optovia.ru'], credentials: true }))
|
|
|
|
const publicServer = new ApolloServer<AuthContext>({
|
|
typeDefs: publicTypeDefs,
|
|
resolvers: publicResolvers,
|
|
introspection: true,
|
|
})
|
|
|
|
const userServer = new ApolloServer<AuthContext>({
|
|
typeDefs: userTypeDefs,
|
|
resolvers: userResolvers,
|
|
introspection: true,
|
|
})
|
|
|
|
const m2mServer = new ApolloServer<AuthContext>({
|
|
typeDefs: m2mTypeDefs,
|
|
resolvers: m2mResolvers,
|
|
introspection: true,
|
|
})
|
|
|
|
await Promise.all([publicServer.start(), userServer.start(), m2mServer.start()])
|
|
|
|
app.use(
|
|
'/graphql/public',
|
|
express.json(),
|
|
expressMiddleware(publicServer, {
|
|
context: async ({ req }) => publicContext(req as unknown as import('express').Request),
|
|
}) as unknown as express.RequestHandler,
|
|
)
|
|
|
|
app.use(
|
|
'/graphql/user',
|
|
express.json(),
|
|
expressMiddleware(userServer, {
|
|
context: async ({ req }) => userContext(req as unknown as import('express').Request),
|
|
}) as unknown as express.RequestHandler,
|
|
)
|
|
|
|
app.use(
|
|
'/graphql/m2m',
|
|
express.json(),
|
|
expressMiddleware(m2mServer, {
|
|
context: async () => m2mContext(),
|
|
}) as unknown as express.RequestHandler,
|
|
)
|
|
|
|
app.get('/health', (_, res) => {
|
|
res.json({ status: 'ok' })
|
|
})
|
|
|
|
app.listen(PORT, '0.0.0.0', () => {
|
|
console.log(`KYC server ready on port ${PORT}`)
|
|
console.log(` /graphql/public - public (optional auth)`)
|
|
console.log(` /graphql/user - id token auth`)
|
|
console.log(` /graphql/m2m - internal services (no auth)`)
|
|
})
|