-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathapp.js
33 lines (29 loc) · 922 Bytes
/
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
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var cors = require('cors')
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
const postRouter = require('./routes/posts');
const mongoose = require('mongoose');
const dotenv = require('dotenv');
var app = express();
dotenv.config({ path: './config.env' });
const DB = process.env.DATABASE.replace(
'<password>',
process.env.DATABASE_PASSWORD
);
mongoose
.connect(DB)
.then(() => console.log('資料庫連接成功'));
app.use(cors())
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/posts', postRouter);
module.exports = app;