Spaces:
Sleeping
Sleeping
| // backend/src/app.ts | |
| import express from 'express'; | |
| import cors from 'cors'; | |
| import cookieParser from 'cookie-parser'; | |
| import { errorHandler } from './utils/errorHandler'; | |
| import { postsRouter } from './posts/router'; | |
| import { notesRouter } from './notes/router'; | |
| import { blogsRouter } from './blogs/router'; | |
| import { projectsRouter } from './projects/router'; | |
| import { uploadsRouter } from './uploads/router'; | |
| import { tagsRouter } from './tags/router'; | |
| import { authRouter } from './auth/router'; | |
| export const app = express(); | |
| // CORS ์ค์ (ํ๋ก ํธ์๋ ๋๋ฉ์ธ ๋ช ์) | |
| app.use(cors({ | |
| origin: process.env.FRONTEND_ORIGIN, // ํ๋ก ํธ์๋ App Service ๋๋ฉ์ธ | |
| credentials: true, // ์ฟ ํค ํ์ฉ | |
| })); | |
| // JSON ํ์ | |
| app.use(express.json({ limit: '5mb' })); | |
| // ์ฟ ํค ํ์ | |
| app.use(cookieParser()); | |
| // ๋ผ์ฐํฐ ์ฐ๊ฒฐ | |
| app.use('/api/posts', postsRouter); | |
| app.use('/api/notes', notesRouter); | |
| app.use('/api/blogs', blogsRouter); | |
| app.use('/api/projects', projectsRouter); | |
| app.use('/api/uploads', uploadsRouter); | |
| app.use('/api/tags', tagsRouter); | |
| app.use('/api/auth', authRouter); | |
| // ๊ธฐ๋ณธ ์๋ด ํ์ด์ง (๋ฃจํธ ๊ฒฝ๋ก) | |
| app.get("/", (req, res) => { | |
| res.send(` | |
| <h1>Portfolio Core Backend</h1> | |
| <p>โ Backend is running.</p> | |
| <p>API endpoints are available under <code>/api/*</code>.</p> | |
| <p>Frontend: <a href="${process.env.FRONTEND_ORIGIN}">${process.env.FRONTEND_ORIGIN}</a></p> | |
| `); | |
| }); | |
| // ํฌ์ค์ฒดํฌ ์๋ํฌ์ธํธ | |
| app.get("/health", (req, res) => { | |
| res.json({ status: "ok", timestamp: new Date().toISOString() }); | |
| }); | |
| // ์๋ฌ ํธ๋ค๋ฌ | |
| app.use(errorHandler); | |