Free CORS proxy for everyone.
Usage: https://xors.herokuapp.com/https://api.github.com/
- No size limitation
- Support most common methods:
GET
,HEAD
,POST
,PUT
,PATCH
andDELETE
*.log | |
.pnp* | |
node_modules | |
coverage | |
.nyc_output | |
dist | |
lib | |
bin | |
*.tgz | |
tmp | |
.DS_Store | |
thumbs.db |
Free CORS proxy for everyone.
Usage: https://xors.herokuapp.com/https://api.github.com/
GET
, HEAD
, POST
, PUT
, PATCH
and DELETE
{ | |
"name": "xors", | |
"version": "0.0.1", | |
"main": "server.js", | |
"license": "Unlicense", | |
"dependencies": { | |
"cors": "^2.8.5", | |
"express": "^4.16.4", | |
"node-fetch": "^2.3.0" | |
} | |
} |
const express = require('express') | |
const cors = require('cors') | |
const fetch = require('node-fetch') | |
const toObject = it => | |
Object.assign(...Array.from( | |
it.entries(), | |
([key, value]) => ({[key]: value}) | |
)) | |
const app = express() | |
app.use(cors({origin: true})) | |
app.use(/\/http.+/, (req, res, next) => { | |
const url = decodeURIComponent(req.originalUrl.slice(1)) | |
const init = { | |
method: req.method, | |
headers: req.headers, | |
...(/head|get/i.test(req.method)? {}: {body: req}) | |
} | |
fetch(url, init) | |
.then(result => { | |
res.status(result.status) | |
res.set(toObject(result.headers)) | |
result.body.pipe(res) | |
}) | |
.catch(e => { | |
console.log(e) | |
res.status(502).json(e) | |
}) | |
}) | |
app.listen(process.env.PORT) |