Skip to content

Commit

Permalink
reverse proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
malipetek authored Jun 4, 2022
1 parent 7add748 commit f21e2b3
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const dotenv = require('dotenv').config();
require('isomorphic-fetch');
const express = require('express');
const app = express();
const crypto = require('crypto');
Expand All @@ -23,6 +24,19 @@ app.get('/', (req, res) => {
res.send('Hello Justin!');
});

app.get('/reverse-proxy', async (req, res) => {
const url = req.query.url;
const response = await fetch(url);
const responseContent = await response.text();
// set fetch response headers to res headers
// [...response.headers].forEach(([key, value]) => {
// res.setHeader(key, value);
// });
// set cors headers
res.setHeader('Content-Type', 'application/javascript');
res.setHeader('Access-Control-Allow-Origin', '*');
res.send(responseContent);
});

// Shopify install route
app.get('/shopify', (req, res) => {
Expand Down
94 changes: 94 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"cookie": "^0.4.1",
"dotenv": "^16.0.0",
"express": "^4.17.2",
"isomorphic-fetch": "^3.0.0",
"nonce": "^1.0.4",
"request": "^2.88.2",
"request-promise": "^4.2.6"
Expand Down

0 comments on commit f21e2b3

Please sign in to comment.