-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
46 lines (34 loc) · 1.1 KB
/
app.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
var path = require('path');
var express = require('express');
var app = express();
var connectingDB = require(path.resolve(__dirname, './mongodb')).connectingDB;
var objectId = require(path.resolve(__dirname, './mongodb')).objectId;
var createRouter = require(path.resolve(__dirname, './create'));
var readRouter = require(path.resolve(__dirname, './read'));
var updateRouter = require(path.resolve(__dirname, './update'));
var deleteRouter = require(path.resolve(__dirname, './delete'));
var compression = require('compression');
var morgan = require('morgan');
connectingDB
.then(db => {
app.use(morgan('short'));
app.use('/static', express.static(path.resolve(__dirname, './static')));
app.get('/', (req, res) => {
res.sendFile(path.resolve(__dirname, './static/blog.html'));
});
app.use(compression());
app.use((req, res, next) => {
req.db = db;
req.objectId = objectId;
next();
});
// Create
app.post('/api', createRouter);
// Read
app.get('/api', readRouter);
// Update
app.put('/api', updateRouter);
// Delete
app.delete('/api', deleteRouter);
app.listen(1688);
});