Last active
January 3, 2020 17:59
-
-
Save odedw/b7684cebb409165e5e227ac10ef82ebe to your computer and use it in GitHub Desktop.
Reverse Proxy
This file contains hidden or 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
function handleRequest(request) { | |
const firstSegment = getFirstSegmentOfPath(request); | |
const destinationApp = config.apps.find((app) => firstSegment === app.path); | |
if (destinationApp) { | |
proxyRequestToDomain(destinationApp.domain); | |
return; | |
} | |
proxyRequestToApp(config.defaultDomain); | |
} |
This file contains hidden or 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
type App = { | |
path: string; | |
targetDomain: string; | |
}; | |
type Config = { | |
defaultDomain: string; | |
apps: App[]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment