Skip to content

Instantly share code, notes, and snippets.

@tanduong
Created November 5, 2018 04:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanduong/c49919c93fffea6cf94e9cde05dd9b8a to your computer and use it in GitHub Desktop.
Save tanduong/c49919c93fffea6cf94e9cde05dd9b8a to your computer and use it in GitHub Desktop.
proxy and edit graphql response
const express = require('express');
const bodyParser = require('body-parser');
const axios = require('axios');
const app = express();
const cors = require('cors');
app.use(cors());
app.use(bodyParser.json());
const backend = 'https://marketplace-api.qa.kamereo.vn/graphql';
app.post('/graphql', function(req, res) {
axios
.post(backend, req.body)
.then(function(response) {
try {
const {data, errors, dataPresent, extensions} = response.data;
res.json({
data,
errors: errors.length > 0 ? errors : null,
dataPresent,
extensions,
});
} catch (error) {
console.error(error);
res.json({});
}
})
.catch(function(error) {
console.log(error);
});
});
const server = require('http').createServer(app);
server.listen(3333);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment