Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
/node_modules
/dist
/data
src/client.ts
src/datos.ts
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"ajv": "^6.12.2",
"axios": "^0.19.2",
"bcryptjs": "^2.4.3",
"dotenv": "^8.2.0",
Comment thread
saullopezc marked this conversation as resolved.
Outdated
"express": "^4.17.1",
"ts-node-dev": "^1.0.0-pre.44"
},
Expand Down
38 changes: 38 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { resolve } from 'path';
import {config} from 'dotenv';
import axios from 'axios'
import { datos } from './datos'

Comment thread
saullopezc marked this conversation as resolved.
Outdated
config({path: resolve(__dirname, "./.env")});

const url = 'http://95.217.235.69/'
// const url = 'http://localhost/'
Comment thread
saullopezc marked this conversation as resolved.
Outdated

export const getInfo = async () => {
datos.credentials.password = process.env.PASSWORD
const urlString = url+datos.contactInfo.emailAddress

const data = await axios.get(urlString ,{
headers: {
"Content-Type": "application/json",
"x-password": datos.credentials.password
}
}).then(res => {
return res.data
}).catch(err => {
return err
})

return data
}

export const sendInfo = async () => {
datos.credentials.password = process.env.PASSWORD
const data = axios.post(url,datos).then(res => {
return (res.status, res.data)
}).catch(err => {
return err
})
return data
}

35 changes: 34 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,42 @@ import express from "express";
import fs from "fs";
import schema from "./schema.json";
import server from "./server";
import { sendInfo, getInfo } from './client';

Comment thread
saullopezc marked this conversation as resolved.
export const router = express.Router({
strict: true,
});

// mis rutas
server.get("/setData", async (req: Request, res: Response) => {
try{
const datos = await sendInfo()
res.json({
datos
})
} catch(err){
res.json({
status: "400",
message: err
})
}
})

server.get("/getData", async (req: Request, res: Response) => {

try {

const datos = await getInfo()
res.json({
datos
})
} catch(error){
res.json({
error
})
}
})

server.get("/:emailAddress", async (req: Request, res: Response) => {
const message =
"Acceso inválido mi chavo. ¿Proporcionaste la contraseña en el parámetro x-password de los headers?";
Expand Down Expand Up @@ -64,7 +95,7 @@ server.post("/", async (req: Request, res: Response) => {
}

const fileName = req.body?.contactInfo?.emailAddress;

req.body.credentials.password = await hash(
req.body.credentials.password,
await genSalt(),
Expand All @@ -87,6 +118,8 @@ server.post("/", async (req: Request, res: Response) => {
}
});



server.listen("80", () => {
console.log("listening");
});
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ diff@^4.0.1:
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==

dotenv@^8.2.0:
Comment thread
saullopezc marked this conversation as resolved.
Outdated
version "8.2.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a"
integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==

dynamic-dedupe@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/dynamic-dedupe/-/dynamic-dedupe-0.3.0.tgz#06e44c223f5e4e94d78ef9db23a6515ce2f962a1"
Expand Down