-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
38 lines (29 loc) · 925 Bytes
/
index.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
var express = require('express');
var app = express();
var cors = require('cors');
var database = require('./config/database');
var port = process.env.PORT || 3005;
// Connect to our database
database.connect((err) => {
if (err) throw err;
});
// This is to allow our api for cross-origin resource sharing
app.use(cors());
// This is to allow our api for parsing json
app.use(express.json());
// This is to allow our api to receive data from a client app
app.use(express.urlencoded({
extended: true
}));
// Register routes in the main index.js
app.use('/', [
require('./routes/tweet'),
require('./routes/auth')
]);
// http://localhost:3005/tweets - GET, POST
// http://localhost:3005/tweets/user/:id - GET
// http://localhost:3005/tweets/:id - DELETE
// http://localhost:3005/authenticate - POST for login session
app.listen(port, () => {
console.log(`Listening at http://localhost:${port}`);
});