-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (34 loc) · 1.06 KB
/
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
const express = require("express")
const app = express()
const router = express.Router()
const path = require('path')
const mongoose = require("mongoose")
const config = require('./config/databse')
const bodyParser = require("body-parser")
const authentiation = require('./routes/authentication')(router)
const blogs = require('./routes/blog')(router)
const cors = require("cors")
const port=process.env.PORT || 8080
mongoose.Promise = global.Promise
mongoose.connect(config.uri,{ useCreateIndex: true,useNewUrlParser: true }, (err) => {
if (err) {
console.log(err)
} else {
// console.log(config.secret)
console.log("connected: " + config.db)
}
})
app.use(cors({
origin: 'http://localhost:4200'
}))
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(express.static(__dirname + '/public/'))
app.use('/authentication', authentiation)
app.use('/blogs', blogs)
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname + '/public/index.html'))
})
app.listen(port, (err) => {
console.log("runing")
})