Compare commits
	
		
			4 Commits
		
	
	
		
			eb4c45f4cf
			...
			7504dcdb79
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 7504dcdb79 | |||
| 8e3358d55d | |||
| a0816fba9e | |||
| 873bf91f81 | 
							
								
								
									
										38
									
								
								Readme.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								Readme.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,38 @@ | |||||||
|  | # 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,6 +1,15 @@ | |||||||
| Bun.serve({ | Bun.serve({ | ||||||
|   port: 8080, |   port: 8080, | ||||||
|   fetch(req, res) { |   fetch(req) { | ||||||
|     return Response.redirect("https://git.cbraaten.dev", 302); |     const url = new URL(req.url); | ||||||
|  |     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