-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
50 lines (35 loc) · 1.22 KB
/
server.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
//Dependencias
const express = require('express');
const path = require('path');
const http = require('http');
const bodyParser = require('body-parser');
///BANCO
var mongoose = require('mongoose');
mongoose.connect('mongodb://phlelism:[email protected]:27017,cluster0-shard-00-01-2ehrn.mongodb.net:27017,cluster0-shard-00-02-2ehrn.mongodb.net:27017/Cluster0?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin');
var Restaurante = require('./server/models/restaurante');
//Rotas
const api = require('./server/routes/api');
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
//Dist
app.use(express.static(path.join(__dirname, 'dist')));
//Seta Rotas
app.use('/api', api);
//Retorna a index para todas as outras rotas
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'dist/index.html'));
});
/**
* Pega porta e guarda no Express
*/
const port = process.env.PORT || '3000';
app.set('port', port);
/**
* Cria o servidor HTTP.
*/
const server = http.createServer(app);
/**
* Escuta a porta
*/
server.listen(port, () => console.log(`Aplicação rodando no localhost:${port}`));