-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
32 lines (25 loc) · 782 Bytes
/
server.js
File metadata and controls
32 lines (25 loc) · 782 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
import express from 'express';
import cors from 'cors';
import 'dotenv/config';
import { clerkMiddleware, getAuth } from '@clerk/express'
import aiRouter from './routes/airoutes.js';
const app = express();
app.use(cors());
app.use(express.json());
app.use(clerkMiddleware());
app.get('/', (req, res) => {
res.send('QuickAi Server is running...');
});
// Protect all routes below this point — replaces deprecated requireAuth()
app.use((req, res, next) => {
const { userId } = getAuth(req);
if (!userId) {
return res.status(401).json({ success: false, message: 'Unauthenticated' });
}
next();
});
app.use('/api/ai',aiRouter)
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});