Created
January 15, 2019 01:51
-
-
Save conanak99/95b4bf2f9fcc580c6f9ce425a30a6380 to your computer and use it in GitHub Desktop.
This file contains 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
'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