-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
34 lines (26 loc) · 1017 Bytes
/
app.js
File metadata and controls
34 lines (26 loc) · 1017 Bytes
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
//Crea el servidor
const express = require('express'); // Importa express
const helmet = require('helmet'); // Seguridad HTTP
const app = express(); // Crear el servidor
const port = 3000; // Elegir puerto http
//IMPORTAR ROUTES
const entriesRoutes = require("./routes/entries.routes");
const authorsRoutes = require("./routes/authors.routes")
// Para poder hacer el POST necesito esto:
app.use(express.json()); // permite leer el body en POST/PUT/DELETE | Habilitar recepción de JSON por mi backend , parsear el "body" entrante a JSON
app.use(helmet());
// Ruta de prueba
app.get("/", (req, res) => {
res.send("API funcionando 🚀");
});
// Rutas
//API montamos routers
//http//localhost:3000/api/entries
app.use('/api/entries',entriesRoutes);// Habilitar rutas
//http//localhost:3000/api/authors
app.use('/api/authors',authorsRoutes);
// Levantar servidor
//http://localhost:3000
app.listen(port, () => { // Activar servidor en puerto 3000
console.log(`Example app listening on port ${port}`)
});