Migrate billing backend from Django to Express + Apollo Server + Prisma
All checks were successful
Build Docker Image / build (push) Successful in 1m44s
All checks were successful
Build Docker Image / build (push) Successful in 1m44s
Replace Python/Django/Graphene with TypeScript/Express/Apollo Server. Same 2 endpoints (team/m2m), same JWT auth, same TigerBeetle integration. Prisma ORM replaces Django ORM for Account/OperationCode/ServiceAccount.
This commit is contained in:
64
src/index.ts
Normal file
64
src/index.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
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 { teamTypeDefs, teamResolvers } from './schemas/team.js'
|
||||
import { m2mTypeDefs, m2mResolvers } from './schemas/m2m.js'
|
||||
import { m2mContext, 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 teamServer = new ApolloServer<AuthContext>({
|
||||
typeDefs: teamTypeDefs,
|
||||
resolvers: teamResolvers,
|
||||
introspection: true,
|
||||
})
|
||||
|
||||
const m2mServer = new ApolloServer<AuthContext>({
|
||||
typeDefs: m2mTypeDefs,
|
||||
resolvers: m2mResolvers,
|
||||
introspection: true,
|
||||
})
|
||||
|
||||
await Promise.all([teamServer.start(), m2mServer.start()])
|
||||
|
||||
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.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(`Billing server ready on port ${PORT}`)
|
||||
console.log(` /graphql/team - team access token auth`)
|
||||
console.log(` /graphql/m2m - internal services (no auth)`)
|
||||
})
|
||||
Reference in New Issue
Block a user