-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
55 lines (48 loc) · 1.34 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
47
48
49
50
51
52
53
54
55
/*
* @Author:
* @Date: 2023-02-22 01:39:44
* @LastEditors: Please set LastEditors
* @LastEditTime: 2023-02-23 23:21:10
* @Description:
*/
const express = require('express');
const routes = require('./routes/');
const mongoose = require('mongoose');
const cors = require('cors');
const bodyParser = require('body-parser');
const helmet = require('helmet');
const cloudinary = require('cloudinary');
const path = require('path');
const cookieParser = require('cookie-parser');
const app = express();
const router = express.Router();
const url = process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/medium';
cloudinary.config({
cloud_name: 'chidumennamdi',
api_key: '',
api_secret: '',
});
mongoose
.connect(url, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
mongoose.set('debug', false);
console.log('数据库连接成功');
})
.catch((err) => {
console.log('数据库连接失败,重复,数据库连接失败.');
console.error(err);
});
let port = process.env.PORT || 5000;
routes(router);
app.use(cors());
app.use(bodyParser.json());
app.use(cookieParser());
app.use(helmet());
app.use('/static', express.static(path.join(__dirname, 'static')));
app.use('/api', router);
app.listen(port, () => {
console.log(`Server started at port: ${port}`);
});