-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
47 lines (37 loc) · 1.13 KB
/
server.js
File metadata and controls
47 lines (37 loc) · 1.13 KB
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
const jsonServer = require('json-server')
const auth = require('json-server-auth')
const server = jsonServer.create()
const router = jsonServer.router('db.json')
const middlewares = jsonServer.defaults()
// Set default middlewares (logger, static, cors and no-cache)
server.use(middlewares)
// Customiza retorno do metodo Get
router.render = (req, res) => {
const data = res.locals.data;
if (data && data instanceof Array) {
res.jsonp({
items: data,
hasNext: false
})
} else {
res.jsonp(data)
}
}
server.db = router.db
// Use default router
server.use(auth)
server.use(router)
server.listen(3000, () => {
console.log('JSON Server is running')
})
//Importa as dependências que acabamos de instalar
const express = require('express');
const path = require('path');
const app = express();
// Serve os arquivos estáticos da pasta dist (gerada pelo ng build)
app.use(express.static(__dirname + '/dist/angularapp'));
app.get('/*', function(req,res) {
res.sendFile(path.join(__dirname+'/dist/angularapp/index.html'));
});
// Inicia a aplicação pela porta configurada
app.listen(process.env.PORT || 4200);