Добавил валидацию кода подключения

Добавил код ошибки 404 при подключении к несуществующей комнате
This commit is contained in:
2020-09-28 18:57:13 +03:00
parent c1c375d25e
commit b119ced98d
3 changed files with 35 additions and 13 deletions

View File

@@ -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();
});
});