Skip to content

Commit

Permalink
🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
MatiSierraDev committed Nov 4, 2021
0 parents commit 70fadac
Show file tree
Hide file tree
Showing 9 changed files with 1,083 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PORT=8000
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


node_modules/
25 changes: 25 additions & 0 deletions app.js
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();
51 changes: 51 additions & 0 deletions controllers/users.js
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,
};
47 changes: 47 additions & 0 deletions models/server.js
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;
Loading

0 comments on commit 70fadac

Please sign in to comment.