Created
December 3, 2018 18:48
-
-
Save cesarvr/d9fe6b6fdf8b8f3bba196654141507ef to your computer and use it in GitHub Desktop.
Creating a simple ambassador container to override 404 HTTP responses.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let { Ambassador } = require('../node-ambassador/') | |
const TARGET = process.env['target_port'] || 8087 | |
const PORT = process.env['port'] || 8080 | |
const HTTP404 = `const HTTP404 = | |
HTTP/1.0 404 File not found | |
Server: Sitio 💥 | |
Date: ${Date()} | |
Content-Type: text/html | |
Connection: close | |
<body> | |
<H1>Look Somewhere Else / Not Found</H1> | |
<img src="https://www.wykop.pl/cdn/c3201142/comment_E6icBQJrg2RCWMVsTm4mA3XdC9yQKIjM.gif"> | |
</body>` | |
function override_404({service, server}) { | |
service.on('http:404', () => server.respond(HTTP404)) | |
} | |
new Ambassador({port: PORT, target: TARGET}) | |
.tunnel({override_404}) | |
console.log(`listening for request in ${PORT} and targeting ${TARGET}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment