microgen-client
Advanced tools
Comparing version 0.0.2 to 0.0.3
51
index.js
const http = require('http'); | ||
const url = 'http://localhost:3000'; | ||
const client = () => { | ||
const generate = () => { | ||
return new Promise((resolve, reject) => { | ||
http.get(`http://localhost:3000/client?clientId=${process.env.MICROGEN_CLIENT_ID}&clientSecret=${process.env.MICROGEN_CLIENT_SECRET}`, (resp) => { | ||
http.get(`${url}/client?clientId=${process.env.MICROGEN_CLIENT_ID}&clientSecret=${process.env.MICROGEN_CLIENT_SECRET}`, (resp) => { | ||
let data = ''; | ||
@@ -19,3 +20,2 @@ | ||
} else { | ||
throw new Error("Unathorized"); | ||
resolve("failed"); | ||
@@ -26,3 +26,2 @@ } | ||
}).on("error", (err) => { | ||
throw new Error("Unathorized"); | ||
resolve("failed") | ||
@@ -33,5 +32,47 @@ }); | ||
const client = (clientId) => { | ||
return new Promise((resolve, reject) => { | ||
http.get(`${url}/client/${clientId}`, (resp) => { | ||
let data = ''; | ||
// A chunk of data has been recieved. | ||
resp.on('data', (chunk) => { | ||
data += chunk; | ||
}); | ||
// The whole response has been received. Print out the result. | ||
resp.on('end', () => { | ||
const response = JSON.parse(data); | ||
if(response.status == 'success') { | ||
resolve(data); | ||
} else { | ||
reject("failed"); | ||
} | ||
}); | ||
}).on("error", (err) => { | ||
reject("failed") | ||
}); | ||
}) | ||
} | ||
const middleware = ({ app, clientId }) => (req, res, next) => { | ||
if(!app.get("microgen") && clientId) { | ||
client(clientId) | ||
.then(res => { | ||
console.log(res) | ||
console.log(req.hostname) | ||
}) | ||
.catch(err => { | ||
console.log(err); | ||
}) | ||
} else { | ||
next(); | ||
} | ||
} | ||
module.exports = { | ||
client | ||
generate, | ||
middleware | ||
} | ||
{ | ||
"name": "microgen-client", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1913
64