-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.ts
33 lines (26 loc) · 869 Bytes
/
server.ts
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
import cors from "cors";
import { RegisterRoutes } from "../build/routes.ts";
import express from "express";
import * as path from "node:path";
import { toNodeHandler } from "better-auth/node";
import { auth } from "./lib/auth/auth.ts";
import { errorHandler } from "./lib/auth/errorHandler.ts";
import { apiReference } from "@scalar/express-api-reference";
const app = express();
app.all("/auth/*", toNodeHandler(auth));
app.use(express.json());
app.use(cors({ origin: "*" }));
app.get("/openapi.json", (req, res) => res.sendFile(path.join(__dirname, "..", "build", "openapi.json")));
app.use(
"/api-docs",
apiReference({
theme: "purple",
spec: {
url: "/openapi.json"
}
})
);
app.get("/api", (req, res) => res.redirect("/api-docs"));
RegisterRoutes(app);
app.use(errorHandler);
app.listen(8000, () => console.log("Server is running on port 8000"));