-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
48 lines (38 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
const express = require('express')
const mongoose = require('mongoose')
const bodyParser = require('body-parser')
const path = require('path')
const cors = require('cors')
const { send } = require('process')
const passport = require('passport')
const app = express()
app.use(bodyParser.urlencoded({
extended: false
}))
app.use(bodyParser.json())
app.use(cors())
app.use(express.static(path.join(__dirname, 'public')))
app.use(passport.initialize())
require('./config/passport')(passport)
//Qualsiasi altra richiesta che non sia una inclusa in api/users verrà indirizzata verso 'public/index.html
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'public/index.html'))
})
// app.get('/', (req,res) => {
// res.send("<h1>Hello</h1>")
// })
//localhost:5000/routes/api/users = localhost:5000/api/users
const users = require('./routes/api/users')
app.use('/api/users', users)
//localhost:5000/routes/api/users = localhost:5000/pincopallino
// app.use('/pincopallino', users)
const dbUrl = require('./config/keys').mongoURI
mongoose.connect(dbUrl, {useNewUrlParser:true} ).then( () => {
console.log(`Database connected succesfully: ${dbUrl}`)
}).catch( err => {
console.log(`Unable to connect with database ${err}`)
})
const PORT = process.env.PORT || 5000
app.listen(PORT, () => {
console.log(`Server started at PORT ${PORT}`)
})