Skip to content

Commit

Permalink
CORS enabled
Browse files Browse the repository at this point in the history
Castrogiovanni20 committed Oct 27, 2020
1 parent cacf2d8 commit e80b9db
Showing 7 changed files with 990 additions and 30 deletions.
16 changes: 16 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"env": {
"browser": true,
"node": true,
"es6": true
},
"parser": "babel-eslint",
"extends": ["eslint:recommended"],
"rules": {
"no-undef": 2,
"no-var": 2,
"no-const-assign": 2,
"no-unused-vars": 2,
"prefer-const": 2
}
}
18 changes: 8 additions & 10 deletions controller/bancosController.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
const dolarSi = require('../services/dolarSiService')

function getDateTime() {
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth()+1;
var day = now.getDate();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
const now = new Date();
const year = now.getFullYear();
let month = now.getMonth()+1;
let day = now.getDate();
let hour = now.getHours();
let minute = now.getMinutes();
let second = now.getSeconds();
(month.toString().length == 1) ? month = '0'+month : '';
(day.toString().length == 1) ? day = '0'+day : '';
(hour.toString().length == 1) ? hour = '0'+hour : '';
(minute.toString().length == 1)? minute = '0'+minute : '';
(second.toString().length == 1)? second = '0'+second : '';

var dateTime = year+'/'+month+'/'+day+' '+hour+':'+minute+':'+second;
const dateTime = year+'/'+month+'/'+day+' '+hour+':'+minute+':'+second;
return dateTime;
}

16 changes: 8 additions & 8 deletions controller/dolarController.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
function getDateTime() {
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth()+1;
var day = now.getDate();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
const now = new Date();
const year = now.getFullYear();
let month = now.getMonth()+1;
let day = now.getDate();
let hour = now.getHours();
let minute = now.getMinutes();
let second = now.getSeconds();
(month.toString().length == 1) ? month = '0'+month : '';
(day.toString().length == 1) ? day = '0'+day : '';
(hour.toString().length == 1) ? hour = '0'+hour : '';
(minute.toString().length == 1)? minute = '0'+minute : '';
(second.toString().length == 1)? second = '0'+second : '';

var dateTime = year+'/'+month+'/'+day+' '+hour+':'+minute+':'+second;
const dateTime = year+'/'+month+'/'+day+' '+hour+':'+minute+':'+second;
return dateTime;
}

16 changes: 8 additions & 8 deletions controller/riesgoController.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
function getDateTime() {
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth()+1;
var day = now.getDate();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
const now = new Date();
const year = now.getFullYear();
let month = now.getMonth()+1;
let day = now.getDate();
let hour = now.getHours();
let minute = now.getMinutes();
let second = now.getSeconds();
(month.toString().length == 1) ? month = '0'+month : '';
(day.toString().length == 1) ? day = '0'+day : '';
(hour.toString().length == 1) ? hour = '0'+hour : '';
(minute.toString().length == 1)? minute = '0'+minute : '';
(second.toString().length == 1)? second = '0'+second : '';

var dateTime = year+'/'+month+'/'+day+' '+hour+':'+minute+':'+second;
const dateTime = year+'/'+month+'/'+day+' '+hour+':'+minute+':'+second;
return dateTime;
}

11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
const express = require('express')
const bodyParser = require('body-parser')
const dotenv = require('dotenv');
require('dotenv').config()
const router = require('./routes/router')
const PORT = process.env.PORT || 7070
const app = express();


app.get('/', async (req, res) => {
try {
res.send("API para obtener las cotizaciones de los distintos tipos de dolar y riesgo pais. La documentacion la podes encontrar en https://github.com/Castrogiovanni20/api-dolar-argentina")
@@ -23,6 +20,14 @@ app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use('/', router)

// CORS
app.use('*',function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*")
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
res.header('Access-Control-Allow-Headers', 'Content-Type')
next();
});

// Starting the server
app.listen(app.get('port'), () => {
console.log('Server running on port ' + PORT)
938 changes: 938 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -4,16 +4,19 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
"start": "node index.js",
"lint": "eslint \"./**/*.js\""
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"axios": "^0.19.2",
"babel-eslint": "^10.1.0",
"body-parser": "^1.19.0",
"dotenv": "^8.2.0",
"eslint": "^7.9.0",
"express": "^4.17.1",
"web": "0.0.2",
"xml-js": "^1.6.11"

0 comments on commit e80b9db

Please sign in to comment.