piyushgarg-dev / vercel-clone

Vercel Clone From Scratch 🚀
https://youtu.be/0A_JpLYG7hM
168 stars 68 forks source link

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

Open kriptonian1 opened 7 months ago

kriptonian1 commented 7 months ago

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 commented 7 months ago

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

ArnabBCA commented 6 months ago

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

kriptonian1 commented 6 months ago

@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 commented 6 months ago

@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 commented 6 months ago

@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

gill0602 commented 2 months ago

I also deleted the bucket and created it again , when I manually run a task it is executed with proper logs but when I do it wiht postman , it shows the following error under the task section of AWS Cluster

Task stopped at: 2024-08-17T14:19:21.063Z ResourceInitializationError: unable to pull secrets or registry auth: The task cannot pull registry auth from Amazon ECR: There is a connection issue between the task and Amazon ECR. Check your task network configuration. RequestError: send request failed caused by: Post "https://api.ecr.ap-south-1.amazonaws.com/": dial tcp 13.234.8.23:443: i/o timeout

Screenshot (77)

gill0602 commented 2 months ago

@piyushgarg-dev Can you please check out this issue?

@kriptonian1