Skip to content

Instantly share code, notes, and snippets.

@conanak99
Created January 15, 2019 01:51
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 conanak99/95b4bf2f9fcc580c6f9ce425a30a6380 to your computer and use it in GitHub Desktop.
Save conanak99/95b4bf2f9fcc580c6f9ce425a30a6380 to your computer and use it in GitHub Desktop.
'use latest';
import { fromExpress } from 'webtask-tools';
import express from 'express';
import logger from 'morgan';
import cors from 'cors';
import bodyParser from 'body-parser';
import url from 'url';
import axios from 'axios';
const app = express();
app.use(bodyParser.json());
app.use(logger('dev'));
app.use(cors());
app.get('/', (req, res) => {
res.status(200).json({status: 'Proxy working OK'});
});
app.get('/characters', (req, res) => {
const marvelEnpoint = 'https://gateway.marvel.com/v1/public/characters';
const queryString = url.parse(req.url).query;
const requestEndpoint = `${marvelEnpoint}?${queryString}`;
axios({
method: 'get',
url: requestEndpoint,
headers: {'Referer': 'https://codepen.io'}
}).then(result => {
const data = result.data;
res.status(200).json(data);
}).catch(error => {
console.log('error', error.data);
});
});
module.exports = fromExpress(app);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment