-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (35 loc) · 1014 Bytes
/
index.js
File metadata and controls
44 lines (35 loc) · 1014 Bytes
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
34
35
36
37
38
39
40
41
42
43
44
import dotenv from "dotenv";
dotenv.config();
import express from 'express';
import cors from "cors";
import { createClient } from '@supabase/supabase-js';
import { PrismaClient } from '@prisma/client';
import authenticate from "./middleware/auth.js";
import { checkRole } from "./middleware/role-check.js";
import mainRouter from "./Routes/index.js";
// Initialize clients
const supabaseUrl = process.env.SUPABASE_URL;
const supabaseKey = process.env.SUPABASE_KEY;
const supabase = createClient(supabaseUrl, supabaseKey);
const prisma = new PrismaClient();
const app = express();
const port = process.env.PORT || 3000;
const allowedOrigins = ['http://localhost:8080'];
app.use(cors({
origin: allowedOrigins,
credentials: true
}));
// Middleware
app.use(express.json());
app.use("/api",mainRouter);
app.use(authenticate);
app.use(checkRole);
// Start server
app.listen(port, () => {
console.log(`Server running on PORT ${port}`);
});
// Export for use in other files
export {
supabase,
prisma
};