-
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 70fadac
Showing
9 changed files
with
1,083 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=8000 |
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,25 @@ | ||
// //WEB SERVER | ||
// const express = require('express'); | ||
// const path = require('path'); | ||
|
||
|
||
// const app = express(); | ||
// const port = process.env.PORT; | ||
|
||
// app.use( express.static( 'public' ) );//middelware | ||
|
||
// app.get('/', ( req, res ) => { //routes | ||
// res.sendFile(path.join( __dirname, '/public/index.html')) | ||
// }) | ||
|
||
// app.listen(port, () => { | ||
// console.log(`Listen on port: ${port}`) | ||
// }); | ||
|
||
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,51 @@ | ||
const { response, request } = require('express'); | ||
|
||
const usersGet = (req = request , res = response) => { | ||
//endpoint | ||
|
||
const { q, nombre, apikey} = req.query; | ||
|
||
res.status(201).json({ | ||
msg: `create GET APi `, | ||
q, | ||
nombre, | ||
apikey | ||
}); | ||
}; | ||
|
||
const usersPost = (req, res = response) => { | ||
//endpoint | ||
|
||
const { name, apellido } = req.body; | ||
|
||
res.status(201).json({ | ||
msg: `create POST APi `, | ||
name, | ||
apellido | ||
}); | ||
}; | ||
|
||
const usersPut = (req, res = response) => { | ||
//endpoint | ||
|
||
const {id} = req.params; | ||
|
||
res.status(201).json({ | ||
msg: `create PUT APi `, | ||
id | ||
}); | ||
}; | ||
|
||
const usersDelete = (req, res = response) => { | ||
//endpoint | ||
res.status(201).json({ | ||
msg: `create DELETE APi `, | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
usersGet, | ||
usersPost, | ||
usersPut, | ||
usersDelete, | ||
}; |
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,47 @@ | ||
const express = require("express"); | ||
const cors = require('cors'); | ||
|
||
class Server { | ||
constructor() { | ||
this.app = express(); | ||
this.port = process.env.PORT; | ||
this.api = '/api/users'; | ||
|
||
//midelware | ||
this.middleware(); | ||
|
||
//routes | ||
this.routes(); | ||
} | ||
|
||
middleware(){ | ||
|
||
this.app.use(cors()); | ||
|
||
//Lectura y parseo del body | ||
this.app.use(express.json()); | ||
|
||
//Directorio publico | ||
this.app.use(express.static('public')); | ||
} | ||
|
||
routes(){ | ||
this.app.use(this.api, require( '../routes/users' )); | ||
|
||
this.app.get('*', (req, res) => { | ||
res.send('Error'); | ||
}) | ||
|
||
this.app.put('*', (req, res) => { | ||
res.send('Error'); | ||
}) | ||
} | ||
|
||
listen(){ | ||
this.app.listen(this.port, () => { | ||
console.log(`Listen on port: ${this.port}`) | ||
}) | ||
} | ||
} | ||
|
||
module.exports = Server; |
Oops, something went wrong.