-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
49 lines (40 loc) · 1.11 KB
/
server.js
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
41
42
43
44
45
46
47
48
49
import express from 'express';
import mongoose from 'mongoose';
import Cards from './dbCards.js';
import Cors from 'cors';
// App Config
const app = express();
const port = process.env.PORT || 8001
const connection_url = 'mongodb+srv://admin:6OtkCWBE9vPMMTS7@cluster0.wvfjp.mongodb.net/tinderdb?retryWrites=true&w=majority'
// Middlewares
app.use(express.json());
app.use(Cors());
// DB config
mongoose.connect(connection_url, {
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true,
});
// API Endpoints
app.get('/', (req, res) => res.status(200).send('Hello World!'));
app.post('/tinder/cards', (req, res) => {
const dbCard = req.body;
Cards.create(dbCard, (err, data) => {
if(err){
res.status(500).send(err)
}else{
res.status(201).send(data)
}
})
});
app.get('/tinder/cards', (req, res) => {
Cards.find((err, data) => {
if(err){
res.status(500).send(err)
}else{
res.status(200).send(data)
}
})
});
// Listener
app.listen(port, () => console.log(`listening on localhost: ${port}`));