mirror of
https://github.com/anatolykopyl/variants.git
synced 2026-03-26 12:54:36 +00:00
Добавил валидацию кода подключения
Добавил код ошибки 404 при подключении к несуществующей комнате
This commit is contained in:
@@ -53,8 +53,12 @@ MongoClient.connect(process.env.DB_CONNECTION, { useUnifiedTopology: true })
|
||||
// id
|
||||
app.get('/api/join/', (req, res) => {
|
||||
rooms.findOne({ "id": req.query.id }).then(room => {
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.write(JSON.stringify(room));
|
||||
if (room !== null) {
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.write(JSON.stringify(room));
|
||||
} else {
|
||||
res.writeHead(404, { 'Content-Type': 'application/json' });
|
||||
}
|
||||
res.end();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user