-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
59 lines (51 loc) · 1.88 KB
/
server.ts
File metadata and controls
59 lines (51 loc) · 1.88 KB
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
50
51
52
53
54
55
56
57
58
59
/**
* @file Implements an Express Node HTTP server. Declares RESTful Web services
* enabling CRUD operations on the following resources:
* <ul>
* <li>users</li>
* <li>tuits</li>
* <li>likes</li>
* <li>follows</li>
* <li>bookmarks</li>
* <li>messages</li>
* </ul>
*
* Connects to a remote MongoDB instance hosted on the Atlas cloud database
* service
*/
import express from 'express';
import UserController from "./controllers/UserController";
import mongoose from 'mongoose';
import bodyParser from "body-parser";
import UserDao from "./daos/UserDao";
import TuitController from "./controllers/TuitController";
import TuitDao from "./daos/TuitDao";
import LikeController from "./controllers/LikeController";
import FollowController from "./controllers/FollowController";
import BookmarkController from "./controllers/BookmarkController";
import MessageController from "./controllers/MessageController";
var cors = require('cors')
// Connect to database
const app = express();
mongoose.connect('mongodb+srv://tangk01:' + process.env.DB_PASSWORD +
'@cluster0.nfgsg.mongodb.net/myFirstDatabase?retryWrites=true&w=majority');
// Creates RESTful API
app.use(express.json());
app.use(cors());
app.get('/hello', (req, res) =>
res.send('Hello World!'));
app.get('/add/:a/:b', (req, res) => {
res.send(req.params.a + req.params.b);
})
const userController = new UserController(app, new UserDao());
const tuitController = new TuitController(app, new TuitDao());
const likesController = LikeController.getInstance(app);
const followsController = FollowController.getInstance(app);
const bookmarkController = BookmarkController.getInstance(app);
const messageController = MessageController.getInstance(app);
/**
* Start a server listening at port 4000 locally
* but use environment variable PORT on Heroku if available.
*/
const PORT = 4000;
app.listen(process.env.PORT || PORT);