Skip to content

Commit

Permalink
[Version 1.0] Cambio de estructura del proyecto | Completo
Browse files Browse the repository at this point in the history
  • Loading branch information
santiagobaronz committed Jan 18, 2023
1 parent 19b692a commit 9c3fb8f
Show file tree
Hide file tree
Showing 250 changed files with 38,050 additions and 1,224 deletions.
110 changes: 110 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/***************************************************************
* Dependencies
***************************************************************/

const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const { default: fetch } = require('node-fetch');
const mysql = require('mysql2');

require('dotenv').config()

const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.json());

/***************************************************************
* Router y EJS
***************************************************************/

app.set('view engine', 'ejs');
app.set('views', __dirname + '/views')
app.use(express.static(__dirname + '/public'))

/***************************************************************
* Database connection
***************************************************************/

const connection = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "santiagobaron"
})

connection.connect(error => {
if(error) throw error;
console.log('Base de datos conectada')
})

module.exports = connection

/***************************************************************
* Routes
***************************************************************/

app.use('/', require('./router/webRoutes'));
app.use('/api', require('./router/apiRoutes'));

/***************************************************************
* Github Login
***************************************************************/

const CLIENT_ID = process.env.CLIENT_ID;
const CLIENT_SECRET = process.env.CLIENT_SECRET;

app.get('/admin/login', (req, res) => {
res.setHeader('Content-type', 'text/html');
res.sendFile('login.html', { root: './public/admin' })
})

app.get('/admin/dashboard', (req, res) => {
res.setHeader('Content-type', 'text/html');
res.sendFile('dashboard.html', { root: './public/admin' })
})

app.get('/security', (req, res) => {

const clientId = parseInt(req.query.clientID);

(parseInt(process.env.STAFF_ID) == clientId) ? res.send(true) :res.send(false)
})


app.get('/api/getAccessToken', async (req, res) =>{

const params = "?client_id=" + CLIENT_ID + "&client_secret=" + CLIENT_SECRET + "&code=" + req.query.code;
await fetch('https://github.com/login/oauth/access_token' + params, {
method: "POST",
headers: {
"Accept": "application/json"
}
})
.then(response => response.json())
.then(response => res.json(response))

})

app.get('/api/getUserData', async (req, res) => {
req.get("Authorization");
await fetch("https://api.github.com/user", {
method: "GET",
headers: {
"Authorization": req.get("Authorization")
}
})
.then(response => response.json())
.then(response => {
(parseInt(process.env.STAFF_ID) == response.id) ? res.json(response) : res.json({msg: "No autorizado"})
})
})


/***************************************************************
* Server
***************************************************************/

const port = process.env.port || 2020;
app.listen(port, () => console.log(`Escuchando en el puerto ${port}...`));
12 changes: 12 additions & 0 deletions node_modules/.bin/ejs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/ejs.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions node_modules/.bin/ejs.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions node_modules/.bin/jake

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions node_modules/.bin/jake.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions node_modules/.bin/jake.ps1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 97 additions & 0 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9c3fb8f

Please sign in to comment.