-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (32 loc) · 1.2 KB
/
index.js
File metadata and controls
40 lines (32 loc) · 1.2 KB
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
import express from 'express';
import cors from 'cors';
import { createServer } from 'http';
import {
findMatchRequest,
deleteMatchRequest,
cancelMatchRequest,
getMatchSession,
} from './controller/matching-controller.js';
import verifyToken from './utils/verifyToken.js';
const app = express();
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cors()); // config cors so that front-end can use
app.options('*', cors());
const router = express.Router();
router.get('/', (_, res) => {
res.send('Hello World from matching-service');
});
// Protected Routes
router.post('/request', verifyToken, findMatchRequest);
router.delete('/request', verifyToken, deleteMatchRequest);
router.get('/sessions/:sessionId', verifyToken, getMatchSession);
router.post('/cancel', verifyToken, cancelMatchRequest);
app.use('/api/match', router).all((_, res) => {
res.setHeader('content-type', 'application/json');
res.setHeader('Access-Control-Allow-Origin', '*');
});
const PORT = process.env.PORT || 8001;
const httpServer = createServer(app);
httpServer.listen(PORT, () => console.log(`matching-service listening on port ${PORT}`));
export default app;