35 lines
769 B
TypeScript
35 lines
769 B
TypeScript
// src/server.ts
|
|
import express from "express";
|
|
import dotenv from "dotenv";
|
|
import authRoutes from "./routes/auth";
|
|
import protectedRoutes from "./routes/protected";
|
|
import cors from "cors";
|
|
import { authMiddleware } from "./middleware/auth";
|
|
import cookieParser from "cookie-parser";
|
|
|
|
dotenv.config();
|
|
|
|
const app = express();
|
|
|
|
app.use(cors({
|
|
origin: "https://papryk.com",
|
|
methods: ["GET", "POST"],
|
|
credentials: true
|
|
}));
|
|
|
|
app.use(express.json());
|
|
app.use(cookieParser())
|
|
|
|
app.use("/auth", authRoutes);
|
|
app.use("/protected", authMiddleware, protectedRoutes);
|
|
|
|
app.get("/health", (_, res) => {
|
|
res.json({ status: "ok" });
|
|
});
|
|
|
|
const PORT = process.env.PORT || 3000;
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`Server running on http://localhost:${PORT}`);
|
|
});
|