-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (30 loc) · 900 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
34
35
36
37
38
39
40
41
require('dotenv').config()
const express = require('express')
const cors = require('cors')
const path = require('path')
const db = require('./config/db.config')
const app = express()
app.use(cors())
app.use(express.json())
app.use(
cors({
credentials: true,
origin: process.env.CORS_ORIGIN //
})
);
db()
app.use('/api', require('./routes/cohort.routes'))
// configurando o express para servir a partir da pasta public
const publicPath = __dirname + '/public';
app.use(express.static(path.join(publicPath)));
app.get('*', (req, res, next) => {
const hostUrl = req.originalUrl;
if (!hostUrl.includes('/api')){
return res.sendFile(path.join(publicPath, 'index.html'))
}
return next()
})
app.use((req, res, next)=> {
res.sendFile(__dirname + '/public/index.html')
})
app.listen(process.env.PORT, () => console.log(`Server up and running on port ${process.env.PORT}`))