Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle non root base path of API Gateway custom domain #78

Closed
jaehyeon-kim opened this issue Dec 20, 2019 · 3 comments
Closed

Handle non root base path of API Gateway custom domain #78

jaehyeon-kim opened this issue Dec 20, 2019 · 3 comments

Comments

@jaehyeon-kim
Copy link

Hi

It fails to map a path correctly if an API is deployed to non root base path (eg /api) of API Gateway custom domain. serverless-wsgi handles it with an environment variable named API_GATEWAY_BASE_PATH - https://github.com/logandk/serverless-wsgi#custom-domain-names. (source - https://github.com/logandk/serverless-wsgi/blob/master/serverless_wsgi.py#L112).

It'll be helpful if the class is updated something similar shown below.

@dataclass
class Mangum:

    app: ASGIApp
    enable_lifespan: bool = True
    api_gateway_base_path: str = None
    log_level: str = "info"

...

    def strip_base_path(self, event: dict):
        path_info = event["path"]
        if self.api_gateway_base_path:
            script_name = "/" + self.api_gateway_base_path
            if path_info.startswith(script_name):
                path_info = path_info[len(script_name) :]
        return urllib.parse.unquote(path_info or "/")

    ....

    def handle_http(self, event: dict, context: dict) -> dict:
        ...
        scope = {
            ...
            "path": self.strip_base_path(event),
            ...
        }
    ...

Thanks.

@jordaneremieff
Copy link
Owner

@jaehyeon-kim thanks for raising this. Would you like to put in PR with your proposed changed? Otherwise I can take a look later.

@jaehyeon-kim
Copy link
Author

Hi @ERM

Please find this PR - #79.

Cheers,
Jaehyeon

@jordaneremieff
Copy link
Owner

Resolved by #79

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants