Skip to content

Commit 581f146

Browse files
committed
feat: healthCheck
1 parent be20651 commit 581f146

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/routers/auth.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ const emailTemplatePath = path.join(__dirname, '../templates/magic-link-email.ht
1313
const emailTemplate = fs.readFileSync(emailTemplatePath, 'utf-8');
1414

1515
export const authRouter = router({
16+
healthCheck: publicProcedure
17+
.query(async () => {
18+
return {
19+
status: 'ok',
20+
timestamp: new Date().toISOString(),
21+
message: 'Backend is online'
22+
};
23+
}),
24+
1625
requestLoginLink: publicProcedure
1726
.input(z.object({ email: z.string().email() }))
1827
.mutation(async ({ input: { email } }) => {

src/server.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,19 @@ export async function createContext({ req }: { req: any }) {
3333

3434
// 3. 创建并配置 Fastify 服务器
3535
const server = fastify({ maxParamLength: 5000 });
36-
server.register(cors);
36+
server.register(cors, {
37+
origin: ['http://localhost:5174', 'http://localhost:3000', 'http://127.0.0.1:5174', 'http://tobenot.top',],
38+
credentials: true
39+
});
3740
server.register(fastifyTRPCPlugin, {
3841
prefix: '/api/trpc',
39-
trpcOptions: { router: appRouter, createContext },
42+
trpcOptions: {
43+
router: appRouter,
44+
createContext,
45+
onError: ({ error }: { error: any }) => {
46+
console.error('tRPC Error:', error);
47+
}
48+
},
4049
});
4150

4251
// 4. 注册静态文件服务

0 commit comments

Comments
 (0)