All checks were successful
Build Docker Image / build (push) Successful in 1m37s
Replace Python/Django/Graphene stack with TypeScript/Express/Apollo Server. Same 3 GraphQL endpoints (public/user/team), same JWT auth via Logto JWKS, same Odoo proxy logic. No database needed (pure proxy).
87 lines
2.3 KiB
TypeScript
87 lines
2.3 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 { teamTypeDefs, teamResolvers } from './schemas/team.js'
|
|
import { publicContext, userContext, teamContext, 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 teamServer = new ApolloServer<AuthContext>({
|
|
typeDefs: teamTypeDefs,
|
|
resolvers: teamResolvers,
|
|
introspection: true,
|
|
})
|
|
|
|
await Promise.all([publicServer.start(), userServer.start(), teamServer.start()])
|
|
|
|
app.use(
|
|
'/graphql/public',
|
|
express.json(),
|
|
expressMiddleware(publicServer, {
|
|
context: async () => publicContext(),
|
|
}) as unknown as express.RequestHandler,
|
|
)
|
|
|
|
app.use(
|
|
'/graphql/user',
|
|
express.json(),
|
|
expressMiddleware(userServer, {
|
|
context: async ({ req }) => {
|
|
try {
|
|
return await userContext(req as unknown as import('express').Request)
|
|
} catch {
|
|
return { scopes: [] }
|
|
}
|
|
},
|
|
}) as unknown as express.RequestHandler,
|
|
)
|
|
|
|
app.use(
|
|
'/graphql/team',
|
|
express.json(),
|
|
expressMiddleware(teamServer, {
|
|
context: async ({ req }) => teamContext(req as unknown as import('express').Request),
|
|
}) as unknown as express.RequestHandler,
|
|
)
|
|
|
|
app.get('/health', (_, res) => {
|
|
res.json({ status: 'ok' })
|
|
})
|
|
|
|
app.listen(PORT, '0.0.0.0', () => {
|
|
console.log(`Orders server ready on port ${PORT}`)
|
|
console.log(` /graphql/public - public`)
|
|
console.log(` /graphql/user - id token auth`)
|
|
console.log(` /graphql/team - team access token auth`)
|
|
})
|