Skip to content

Commit 632d577

Browse files
committed
Set up part of matching service
1 parent d1a103f commit 632d577

File tree

5 files changed

+42
-9
lines changed

5 files changed

+42
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ node_modules/
66

77
# PeerPrep
88
.env
9+
/matching-service/dev.sqlite

matching-service/env.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ENV=DEV
2+
PORT=8001

matching-service/index.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
11
import express from 'express';
22
import cors from 'cors';
3-
import { createServer } from 'http';
3+
import 'dotenv/config';
4+
import db from './model/repository.js';
5+
6+
// const db = import('./model/repository.js');
47

58
const app = express();
6-
app.use(express.urlencoded({ extended: true }))
7-
app.use(express.json())
8-
app.use(cors()) // config cors so that front-end can use
9-
app.options('*', cors())
9+
const port = process.env.PORT || 8001;
10+
11+
app.use(express.json());
12+
app.use(express.urlencoded({ extended: true }));
13+
app.use(cors()); // config cors so that front-end can use
14+
app.options('*', cors()); // TODO: what's this?
1015

11-
app.get('/', (req, res) => {
12-
res.send('Hello World from matching-service');
16+
app.get('/api/matching', (req, res) => {
17+
res.status(200).send('Hello World from matching-service');
1318
});
1419

15-
const httpServer = createServer(app)
20+
try {
21+
db.connection();
22+
} catch (error) {
23+
console.log(error);
24+
}
25+
26+
console.log('Calling app.listen()');
27+
28+
const server = app.listen(port, () => {
29+
console.log('Matching service server started on port ' + port);
30+
}); // TODO: socketio.listen(server)
1631

17-
httpServer.listen(8001);
32+
console.log('app.listen() executed');
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Sequelize } from 'sequelize';
2+
3+
const sequelize = new Sequelize('test-db', 'user', 'password', {
4+
dialect: 'sqlite',
5+
host: './dev.sqlite', // data are stored in the file
6+
});
7+
8+
const connection = async () => {
9+
sequelize.sync().then(() => {
10+
console.log('Connected to DB');
11+
});
12+
};
13+
14+
export default { connection };

matching-service/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"nodemon": "^2.0.19"
1717
},
1818
"dependencies": {
19+
"dotenv": "^16.0.2",
1920
"express": "^4.18.1",
2021
"sequelize": "^6.21.3",
2122
"socket.io": "^4.5.1",

0 commit comments

Comments
 (0)