Last active
May 25, 2020 17:20
-
-
Save Ramko9999/0d772aa284ccf25b28f354016b5f5229 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require("express"); | |
const app = express(); | |
const TigerGraphCred = require("./config.js"); | |
const fetch = require("node-fetch"); | |
app.get("/profile/:id", async(req, res)=>{ | |
const person = req.params.id; | |
const reqUrl = TigerGraphCred.queryUrl + `RP_getProfile?person=${person}`; | |
const response = await fetch(reqUrl, { | |
headers:{ | |
"Content-Type": "application/json", | |
"Authorization": `Bearer ${TigerGraphCred.token}`, | |
"Accept":"application/json" | |
} | |
}); | |
if(response.status === 200){ | |
const json = await response.json(); | |
//query for the error and send appropriate status code and response | |
if(json.error){ | |
res.status(400).send({"error": json.message}); | |
} | |
else{ | |
res.status(200).send(json); | |
} | |
} | |
else{ | |
const message = await response.text(); | |
res.status(500).send({'error': message}); | |
} | |
}); | |
app.listen(5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment