Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to access resource from S3 public server using reverse proxy #13

Open
kriptonian1 opened this issue Mar 29, 2024 · 5 comments
Open

Comments

@kriptonian1
Copy link

output

image

Code

const express = require("express");
const httpProxy = require("http-proxy");

const app = express();
const PORT = 8000;

const BASE_PATH =
    "https://faucet-client-deployments.s3.amazonaws.com/__outputs";

const proxy = httpProxy.createProxy();

app.use((req, res) => {
    const hostname = req.hostname;
    const subdomain = hostname.split(".")[0];

    // Custom Domain - DB Query

    const resolvesTo = `${BASE_PATH}/${subdomain}`;

    return proxy.web(req, res, { target: resolvesTo, changeOrigin: true });
});

proxy.on("proxyReq", (proxyReq, req, res) => {
    const url = req.url;
    console.log("url", url);
    console.log("proxyReq.path", proxyReq.path);
    if (url === "/") proxyReq.path  = "index.html";
});

app.listen(PORT, () => console.log(`Reverse Proxy Running..${PORT}`));

S3 Bucket policy

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "s3:GetObject",
                "s3:GetObjectVersion"
            ],
            "Resource": "arn:aws:s3:::faucet-client-deployments/*"
        },
        {
            "Sid": "AllowWebAccess",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
                "s3:GetObject",
                "s3:GetObjectVersion"
            ],
            "Resource": "arn:aws:s3:::faucet-client-deployments/*"
        }
    ]
}
@kriptonian1
Copy link
Author

@piyushgarg-dev I would really appreciate it if you can help me resolve this

@ArnabBCA
Copy link

@piyushgarg-dev @kriptonian1 I am having same problem have you found any solution? thanks

@kriptonian1
Copy link
Author

@piyushgarg-dev @kriptonian1 I am having same problem have you found any solution? thanks

I just deleted it and created it, and it worked

@ArnabBCA
Copy link

@piyushgarg-dev @kriptonian1 I am having same problem have you found any solution? thanks

I just deleted it and created it, and it worked

You mean the bucket?

@kriptonian1
Copy link
Author

@piyushgarg-dev @kriptonian1 I am having same problem have you found any solution? thanks

I just deleted it and created it, and it worked

You mean the bucket?

Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants