Compare commits
	
		
			No commits in common. "7504dcdb7979503f403a38ac310f069fa23065a3" and "eb4c45f4cfbf595cb31f0128cc364f89ee511f0e" have entirely different histories.
		
	
	
		
			7504dcdb79
			...
			eb4c45f4cf
		
	
		
							
								
								
									
										38
									
								
								Readme.md
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								Readme.md
									
									
									
									
									
								
							| @ -1,38 +0,0 @@ | |||||||
| # DomainRedirect |  | ||||||
| 
 |  | ||||||
| This is a simple http redirect service. It is designed to be used with a domain that is not the primary domain for a website. For example, if you have a website at `example.com` and you want to redirect `example.net` to `example.com`, you can use this service. |  | ||||||
| 
 |  | ||||||
| ### Features |  | ||||||
| - Redirects all requests other than /health to whatever is specified in the `REDIRECT_TARGET` environment variable. |  | ||||||
| - Health check endpoint at `/health` that returns a 200 status code. |  | ||||||
| 
 |  | ||||||
| ### Limitations |  | ||||||
| - Paths are not preserved. For example, if a user goes to `example.net/foo`, they will be redirected to the `REDIRECT_TARGET` such as `example.com`. |  | ||||||
| 
 |  | ||||||
| ## Usage |  | ||||||
| 
 |  | ||||||
| This is not compatible with Node or Deno. It is written to be run with [Bun](https://bun.sh/) |  | ||||||
| 
 |  | ||||||
| ### Run with Bun |  | ||||||
| 
 |  | ||||||
| ```bash |  | ||||||
| REDIRECT_TARGET="https://example.com/" bun run index.js |  | ||||||
| ``` |  | ||||||
| 
 |  | ||||||
| ### Run with Docker |  | ||||||
| 
 |  | ||||||
| 1. Build the image |  | ||||||
| ```bash |  | ||||||
| docker build -t domainredirect . |  | ||||||
| ``` |  | ||||||
| 
 |  | ||||||
| 2. Run the image |  | ||||||
| ```bash |  | ||||||
| docker run -p 8080:8080 -e REDIRECT_TARGET="https://example.com/" domainredirect |  | ||||||
| ``` |  | ||||||
| 
 |  | ||||||
| > Note: If you are building on Apple Silicon and deploying to x86 like me, you will need to build for a [different platform](https://docs.docker.com/build/architecture/) |  | ||||||
| 
 |  | ||||||
| ### Run with Nomad on Docker |  | ||||||
| 
 |  | ||||||
| Check out my [homelab implementation](https://git.cbraaten.dev/Caleb/Homelab/src/branch/main/nomad_jobs/services/domainredirect). |  | ||||||
							
								
								
									
										13
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								index.js
									
									
									
									
									
								
							| @ -1,15 +1,6 @@ | |||||||
| Bun.serve({ | Bun.serve({ | ||||||
|   port: 8080, |   port: 8080, | ||||||
|   fetch(req) { |   fetch(req, res) { | ||||||
|     const url = new URL(req.url); |     return Response.redirect("https://git.cbraaten.dev", 302); | ||||||
|     if (url.pathname === "/health") { |  | ||||||
|       console.log("Health Check"); |  | ||||||
|       return new Response("ok"); |  | ||||||
|     } else { |  | ||||||
|       console.log(`Recieved Request: ${req.method} ${req.url}`); |  | ||||||
|       return Response.redirect(Bun.env.REDIRECT_TARGET, 302); |  | ||||||
|     } |  | ||||||
|   }, |   }, | ||||||
| }); | }); | ||||||
| 
 |  | ||||||
| console.log(`Redirecting Trafic to ${Bun.env.REDIRECT_TARGET}`); |  | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user