-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathapp.ts
More file actions
78 lines (71 loc) · 3.27 KB
/
app.ts
File metadata and controls
78 lines (71 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import path from "node:path"
import { Hono } from "hono"
import { cors } from "hono/cors"
import { logger } from "hono/logger"
import { errorHandler } from "./middleware/error-handler.js"
import { healthRoutes } from "./routes/health.js"
import { createBookRoutes } from "./routes/books.js"
import { createPageRoutes } from "./routes/pages.js"
import { createDebugRoutes } from "./routes/debug.js"
import { createGlossaryRoutes } from "./routes/glossary.js"
import { createQuizRoutes } from "./routes/quizzes.js"
import { createProofService } from "./services/proof-service.js"
import { createProofRunner } from "./services/proof-runner.js"
import { createProofRoutes } from "./routes/proof.js"
import { createPackageRoutes } from "./routes/package.js"
import { createPromptRoutes } from "./routes/prompts.js"
import { createTextCatalogRoutes } from "./routes/text-catalog.js"
import { createTTSRoutes } from "./routes/tts.js"
import { createStageRoutes } from "./routes/stages.js"
import { createStageService } from "./services/stage-service.js"
import { createStageRunner } from "./services/stage-runner.js"
import { createPresetRoutes } from "./routes/presets.js"
import { createAdtPreviewRoutes } from "./routes/adt-preview.js"
import { createSpeechConfigRoutes } from "./routes/speech-config.js"
// Resolve paths relative to monorepo root (2 levels up from apps/api/)
const projectRoot = path.resolve(
process.env.PROJECT_ROOT ?? path.join(process.cwd(), "../..")
)
const booksDir = path.resolve(process.env.BOOKS_DIR ?? path.join(projectRoot, "books"))
const promptsDir = path.resolve(process.env.PROMPTS_DIR ?? path.join(projectRoot, "prompts"))
const configPath = path.resolve(
process.env.CONFIG_PATH ?? path.join(projectRoot, "config.yaml")
)
const webAssetsDir = path.resolve(
process.env.WEB_ASSETS_DIR ?? path.join(projectRoot, "assets", "adt")
)
const proofRunner = createProofRunner()
const proofService = createProofService(proofRunner)
const stageRunner = createStageRunner()
const stageService = createStageService(stageRunner)
const app = new Hono()
app.use("*", logger())
const ALLOWED_ORIGINS = [
"http://localhost:5173", // Vite dev
"tauri://localhost", // Tauri macOS
"https://tauri.localhost", // Tauri Windows
"http://tauri.localhost", // Tauri Linux
]
app.use(
"*",
cors({
origin: ALLOWED_ORIGINS,
})
)
app.onError(errorHandler)
app.route("/api", healthRoutes)
app.route("/api", createBookRoutes(booksDir, webAssetsDir, configPath))
app.route("/api", createPageRoutes(booksDir, promptsDir, configPath))
app.route("/api", createProofRoutes(proofService, booksDir, promptsDir, configPath))
app.route("/api", createGlossaryRoutes(booksDir))
app.route("/api", createDebugRoutes(booksDir, promptsDir, configPath))
app.route("/api", createQuizRoutes(booksDir))
app.route("/api", createPackageRoutes(booksDir, webAssetsDir, configPath))
app.route("/api", createPromptRoutes(promptsDir, booksDir))
app.route("/api", createTextCatalogRoutes(booksDir))
app.route("/api", createTTSRoutes(booksDir))
app.route("/api", createStageRoutes(stageService, booksDir, promptsDir, configPath))
app.route("/api", createPresetRoutes(configPath))
app.route("/api", createAdtPreviewRoutes(booksDir, webAssetsDir, configPath))
app.route("/api", createSpeechConfigRoutes(configPath))
export default app