This repository contains a Node.js application designed to be deployed as a Google Cloud Run service. It provides a dynamic HTTP redirect based on a query parameter that will skip the payload that prevent proper redirection from some website.
The service listens for HTTP GET or POST requests. It expects a query parameter named targetUrl
.
- If
targetUrl
is provided and valid (starts withhttp://
orhttps://
): The service responds with an HTTP 302 Found redirect to the specified URL. - If
targetUrl
is missing, empty, or invalid: The service responds with an HTTP 400 Bad Request error.
Once deployed, you can use the service URL like this:
https://<your-cloud-run-service-url>/?targetUrl=https://www.google.com
Replace <your-cloud-run-service-url>
with the actual URL provided by Cloud Run after deployment. Replace https://www.google.com
with the desired destination URL.
Example:
Accessing https://my-redirector-xyz.a.run.app/?targetUrl=https://developer.mozilla.org
will redirect your browser to https://developer.mozilla.org
.
Accessing https://my-redirector-xyz.a.run.app/
(without the parameter) will result in a "Bad Request" error page.
You can deploy this service directly to Google Cloud Run using the button below:
Deployment Steps:
- Click the "Run on Google Cloud" button.
- If prompted, log in to your Google Cloud account.
- Select or create a Google Cloud Project.
- Choose a Region for deployment.
- Review the default service settings (you can customize them if needed, based on
app.json
). - Click "Deploy".
Cloud Build will build the container image using the included Dockerfile
and deploy it as a Cloud Run service. The service will be configured to allow unauthenticated access by default.
index.js
: The Node.js Cloud Function code using the Functions Framework.package.json
: Defines Node.js dependencies and the start script.Dockerfile
: Instructions for building the container image.app.json
: Configuration for the Cloud Run Button deployment flow.README.md
: This file.
- Install Node.js (version specified in
package.json
). - Install dependencies:
npm install
- Run the function locally:
npm start
- Access in your browser:
http://localhost:8080/?targetUrl=https://example.com