-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6e4a5b3
Showing
10 changed files
with
572 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PORT=8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
|
||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# WebServer + RestServer | ||
|
||
Recuerden que deben de ejecutar ```npm install``` para reconstruir los módulos de Node. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require('dotenv').config(); | ||
const Server = require('./models/server'); | ||
|
||
|
||
const server = new Server(); | ||
|
||
|
||
|
||
server.listen(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const { response, request } = require('express'); | ||
|
||
|
||
const usuariosGet = (req = request, res = response) => { | ||
|
||
const { q, nombre = 'No name', apikey, page = 1, limit } = req.query; | ||
|
||
res.json({ | ||
msg: 'get API - controlador', | ||
q, | ||
nombre, | ||
apikey, | ||
page, | ||
limit | ||
}); | ||
} | ||
|
||
const usuariosPost = (req, res = response) => { | ||
|
||
const { nombre, edad } = req.body; | ||
|
||
res.json({ | ||
msg: 'post API - usuariosPost', | ||
nombre, | ||
edad | ||
}); | ||
} | ||
|
||
const usuariosPut = (req, res = response) => { | ||
|
||
const { id } = req.params; | ||
|
||
res.json({ | ||
msg: 'put API - usuariosPut', | ||
id | ||
}); | ||
} | ||
|
||
const usuariosPatch = (req, res = response) => { | ||
res.json({ | ||
msg: 'patch API - usuariosPatch' | ||
}); | ||
} | ||
|
||
const usuariosDelete = (req, res = response) => { | ||
res.json({ | ||
msg: 'delete API - usuariosDelete' | ||
}); | ||
} | ||
|
||
|
||
|
||
|
||
module.exports = { | ||
usuariosGet, | ||
usuariosPost, | ||
usuariosPut, | ||
usuariosPatch, | ||
usuariosDelete, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const express = require('express'); | ||
const cors = require('cors'); | ||
|
||
class Server { | ||
|
||
constructor() { | ||
this.app = express(); | ||
this.port = process.env.PORT; | ||
this.usuariosPath = '/api/usuarios'; | ||
|
||
// Middlewares | ||
this.middlewares(); | ||
|
||
// Rutas de mi aplicación | ||
this.routes(); | ||
} | ||
|
||
middlewares() { | ||
|
||
// CORS | ||
this.app.use( cors() ); | ||
|
||
// Lectura y parseo del body | ||
this.app.use( express.json() ); | ||
|
||
// Directorio Público | ||
this.app.use( express.static('public') ); | ||
|
||
} | ||
|
||
routes() { | ||
this.app.use( this.usuariosPath, require('../routes/usuarios')); | ||
} | ||
|
||
listen() { | ||
this.app.listen( this.port, () => { | ||
console.log('Servidor corriendo en puerto', this.port ); | ||
}); | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
module.exports = Server; |
Oops, something went wrong.