This application uses the Cloudflare Developer Platform, including Workers and DurableObjects, to implement foundational web application functionality. It acts as a transparent proxy for your application, allowing you to inject custom UI elements and intercept specific paths.
- Transparent Proxying: Forwards requests to your origin application
- HTML Injection: Uses
HTMLRewriterto inject scripts and custom elements (like<power-strip>) into your HTML pages - Path Interception: Intercepts requests to a configurable path to serve internal assets
This is the easiest way to deploy and keep your worker up to date.
- Fork this repository to your account
- Go to your Cloudflare Dashboard's Workers & pages > Create Application
- Click Continue with GitHub
- Select your forked
startup-api-cloudflarerepository - Pick the name for your site's worker (e.g. you might have multiple)
- Deploy the Worker
- In the Settings tab of your Worker, go to Variables and add the required
ORIGIN_URL(see Configuration below)
Use this option if you want to deploy from your local machine.
-
Clone and Install
git clone https://github.com/StartupAPI/startup-api-cloudflare.git cd startup-api-cloudflare npm install -
Configure Environment Variables
Update
wrangler.jsoncor use dashboard Settings tab of your Worker, go to Variables and add the requiredORIGIN_URL(see Configuration below) -
Deploy
npm run deploy
-
Using Cloudflare Dashboard (Recommended):
- Go to Workers & Pages
- Select your worker
- Navigate to Settings > Variables
- Click Add variable under Environment Variables
- Add
ORIGIN_URLand any optional variables - Click Save and deploy
-
Using
wrangler.jsonc: Add the variables to the"vars"object in your configuration file. See Cloudflare documentation for more details.
| Variable | Required | Default | Description |
|---|---|---|---|
ORIGIN_URL |
Yes | N/A | The base URL of your origin application (e.g., https://your-app-origin.com) |
USERS_PATH |
No | /users/ |
The path used to serve internal assets like power-strip.js |
AUTH_ORIGIN |
No | N/A | Optional base URL for OAuth redirects (overrides request origin) |
GOOGLE_CLIENT_ID |
No | N/A | Google OAuth2 Client ID |
GOOGLE_CLIENT_SECRET |
No | N/A | Google OAuth2 Client Secret |
TWITCH_CLIENT_ID |
No | N/A | Twitch OAuth2 Client ID |
TWITCH_CLIENT_SECRET |
No | N/A | Twitch OAuth2 Client Secret |
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Navigate to APIs & Services > Credentials
- Click Create Credentials > OAuth client ID
- Select Web application as the application type
- Add your authorized redirect URI:
https://<your-worker-url>/users/auth/google/callback - Copy the Client ID and Client Secret and add them to your Worker's environment variables
- Go to the Twitch Developer Console
- Register a new application
- Add your authorized redirect URI:
https://<your-worker-url>/users/auth/twitch/callback - Select Website as the category
- Copy the Client ID and generate a Client Secret to add them to your Worker's environment variables
{
"vars": {
"ORIGIN_URL": "https://your-app-origin.com"
}
}- Request Interception: The worker receives all incoming requests
- Path Mapping: If the request path starts with
USERS_PATH, the worker serves assets directly from thepublic/users/directory - Proxying: All other requests are proxied to the configured
ORIGIN_URL - Injection: For
text/htmlresponses, the worker injects a<script>tag and a<power-strip>custom element before serving the content to the user
Contributions are welcome! Please feel free to submit a Pull Request.
Licensed under the Apache License, Version 2.0. See LICENSE for details.