Skip to content

Commit

Permalink
nodemon and catch rev proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
malipetek authored Jun 21, 2022
1 parent 90ae052 commit d8ba56e
Show file tree
Hide file tree
Showing 3 changed files with 2,035 additions and 33 deletions.
52 changes: 28 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,34 @@ app.get('/', (req, res) => {
});

app.use('/reverse-proxy', async (req, res) => {
const url = req.query.url;
const response = await fetch(url, {
method: req.method,
// headers: req.headers,
body: req.body
});
const responseContent = await response.text();
// set fetch response headers to res headers
[...response.headers].forEach(([key, value]) => {
if (key.toLowerCase() == 'access-control-allow-methods') {
res.setHeader(key, value);
}
});
// remove powered-by-express header
res.removeHeader('x-powered-by');
// set cors headers
res.setHeader('Content-Type', 'application/javascript');
res.setHeader('Access-Control-Allow-Origin', '*');
// allow all headers
res.setHeader('Access-Control-Allow-Headers', '*');
// add a cache policy that caches for 1 day
res.setHeader('Cache-Control', 'public, max-age=86400');

res.send(responseContent);
try {
const url = req.query.url;
const response = await fetch(url, {
method: req.method,
// headers: req.headers,
body: req.body
});
const responseContent = await response.text();
// set fetch response headers to res headers
[...response.headers].forEach(([key, value]) => {
if (key.toLowerCase() == 'access-control-allow-methods') {
res.setHeader(key, value);
}
});
// remove powered-by-express header
res.removeHeader('x-powered-by');
// set cors headers
res.setHeader('Content-Type', 'application/javascript');
res.setHeader('Access-Control-Allow-Origin', '*');
// allow all headers
res.setHeader('Access-Control-Allow-Headers', '*');
// add a cache policy that caches for 1 day
res.setHeader('Cache-Control', 'public, max-age=86400');

res.send(responseContent);
} catch (err) {
res.status(500).send('Could not get resource');
}
});

// Shopify install route
Expand Down
Loading

0 comments on commit d8ba56e

Please sign in to comment.