当 url 不包含尾部斜杠时,如何解决 AWS API Gateway 的 404 错误?

问题描述 投票:0回答:1

我已在 AWS API Gateway 上创建了一个 API。我用它来代理静态应用程序,例如名为 Sample-app,我已将其部署到 netlify。

下面附有其openapi配置。

我的问题是:

  • 为什么这不起作用?
  • 如何让API Gateway只添加/?
  • 或者,还有更好的选择吗?
openapi: "3.0.1"
info:
    title: "sample-api"
    version: "2020-04-29T23:24:23Z"
servers:
    - url: "https://sample.com"
paths:
    /apps/sample-app/{proxy+}:
    x-amazon-apigateway-any-method:
        parameters:
        - name: "proxy"
            in: "path"
            required: true
            schema:
            type: "string"
        x-amazon-apigateway-integration:
        uri: "https://sample-app.netlify.app/{proxy}"
        responses:
            default:
            statusCode: "200"
        requestParameters:
            integration.request.path.proxy: "method.request.path.proxy"
        passthroughBehavior: "when_no_match"
        httpMethod: "ANY"
        cacheNamespace: "2ns27y"
        cacheKeyParameters:
            - "method.request.path.proxy"
        type: "http_proxy"
    /apps/sample-app:
    x-amazon-apigateway-any-method:
        responses:
        "200":
            description: "200 response"
            content:
            application/json:
                schema:
                $ref: "#/components/schemas/Empty"
        x-amazon-apigateway-integration:
        uri: "https://sample-app.netlify.app/"
        responses:
            default:
            statusCode: "200"
        passthroughBehavior: "when_no_match"
        httpMethod: "ANY"
        type: "http_proxy"
amazon-web-services redirect aws-api-gateway reverse-proxy openapi
1个回答
0
投票

我不确定您使用的是 HTTP API 还是 REST API,但如果您使用的是 HTTP API,您可以设置

$default
路由作为包罗万象的方法。

https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-routes.html#http-api-develop-routes.default

一旦设置了

$default
路线,您的 https://sample.com/apps/sample-app 就应该可以工作了。

© www.soinside.com 2019 - 2024. All rights reserved.