37 lines
997 B
TypeScript
37 lines
997 B
TypeScript
import "reflect-metadata";
|
|
import express from "express";
|
|
import cors from "cors";
|
|
import dotenv from "dotenv";
|
|
import { AppDataSource } from "./config/data-source";
|
|
import { requireAuth, AuthenticatedRequest } from "./middleware/auth.middleware";
|
|
|
|
dotenv.config();
|
|
|
|
const app = express();
|
|
const PORT = parseInt(process.env.PORT ?? "4000");
|
|
|
|
app.use(cors());
|
|
app.use(express.json());
|
|
|
|
app.get("/api/health", (_req, res) => {
|
|
res.json({ status: "ok", timestamp: new Date().toISOString() });
|
|
});
|
|
|
|
// Route protégée — valide l'intégration SuperOAuth end-to-end
|
|
app.get("/api/profile", requireAuth, (req, res) => {
|
|
const { user } = req as AuthenticatedRequest;
|
|
res.json({ success: true, data: { user } });
|
|
});
|
|
|
|
AppDataSource.initialize()
|
|
.then(() => {
|
|
console.log("Database connected");
|
|
app.listen(PORT, () => {
|
|
console.log(`Server running on port ${PORT}`);
|
|
});
|
|
})
|
|
.catch((err) => {
|
|
console.error("Database connection failed:", err);
|
|
process.exit(1);
|
|
});
|