mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-16 07:39:39 +02:00
Assorted changes from recent sessions: - .gitignore: add mana-sync binary, Forgejo data - chat/web: add isSidebarMode to navigation store - clock/web: fix alarm page markup - contacts/mukke/presi/questions: add svelte.config.js aliases - context/web: add missing dependency - manacore/landing: update pricing page - manacore/web + todo/web: update mana dashboard pages - planta/web: fix dashboard layout - pnpm-lock.yaml: cleanup after backend removals - docs/APP_GAP_ANALYSIS.md: new gap analysis doc - services/mana-analytics: add Dockerfile - services/mana-subscriptions: new Go subscription service Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
/**
|
|
* mana-subscriptions — Subscription & billing service
|
|
*
|
|
* Hono + Bun runtime. Extracted from mana-core-auth.
|
|
* Handles: plans, subscriptions, invoices, Stripe billing.
|
|
*/
|
|
|
|
import { Hono } from 'hono';
|
|
import { cors } from 'hono/cors';
|
|
import { loadConfig } from './config';
|
|
import { getDb } from './db/connection';
|
|
import { errorHandler } from './middleware/error-handler';
|
|
import { jwtAuth } from './middleware/jwt-auth';
|
|
import { serviceAuth } from './middleware/service-auth';
|
|
import { StripeService } from './services/stripe';
|
|
import { SubscriptionsService } from './services/subscriptions';
|
|
import { healthRoutes } from './routes/health';
|
|
import { createSubscriptionRoutes } from './routes/subscriptions';
|
|
import { createInternalRoutes } from './routes/internal';
|
|
import { createWebhookRoutes } from './routes/stripe-webhook';
|
|
|
|
const config = loadConfig();
|
|
const db = getDb(config.databaseUrl);
|
|
|
|
const stripeService = new StripeService(db, config.stripe.secretKey);
|
|
const subscriptionsService = new SubscriptionsService(db, stripeService);
|
|
|
|
const app = new Hono();
|
|
|
|
app.onError(errorHandler);
|
|
app.use('*', cors({ origin: config.cors.origins, credentials: true }));
|
|
|
|
app.route('/health', healthRoutes);
|
|
|
|
// User-facing (JWT auth)
|
|
app.use('/api/v1/subscriptions/*', jwtAuth(config.manaAuthUrl));
|
|
app.route('/api/v1/subscriptions', createSubscriptionRoutes(subscriptionsService));
|
|
|
|
// Service-to-service (X-Service-Key)
|
|
app.use('/api/v1/internal/*', serviceAuth(config.serviceKey));
|
|
app.route('/api/v1/internal', createInternalRoutes(subscriptionsService));
|
|
|
|
// Stripe webhooks (signature verified, no auth)
|
|
app.route(
|
|
'/api/v1/webhooks',
|
|
createWebhookRoutes(stripeService, subscriptionsService, config.stripe.webhookSecret)
|
|
);
|
|
|
|
console.log(`mana-subscriptions starting on port ${config.port}...`);
|
|
|
|
export default {
|
|
port: config.port,
|
|
fetch: app.fetch,
|
|
};
|