小编apr*_*eda的帖子

api网关rest api地理位置标头

我正在使用 AWS SAM CLI

根据https://aws.amazon.com/about-aws/whats-new/2020/07/cloudfront-geolocation-headers/已经支持地理定位,并且 CloudFront 返回地理定位标头;例子:

CloudFront-Viewer-Country-Name: United States
CloudFront-Viewer-Country-Region: MI
CloudFront-Viewer-Country-Region-Name: Michigan
CloudFront-Viewer-City: Ann Arbor
CloudFront-Viewer-Postal-Code: 48105
CloudFront-Viewer-Time-Zone: America/Detroit
CloudFront-Viewer-Latitude: 42.30680
CloudFront-Viewer-Longitude: -83.70590
CloudFront-Viewer-Metro-Code: 505
Run Code Online (Sandbox Code Playgroud)

我希望能够使用我的 API 网关 REST API 访问这些内容,这是我的 aws sam 模板的示例。

Resources:
  login:
    Type: AWS::Serverless::Function
    Properties:
      Handler: src/functions/login.handler
      Runtime: nodejs14.x
      Layers:
        - !Ref dependencies
      Events:
        ApiEvent:
          Type: Api
          Properties:
            Method: post
            Path: /login
            RestApiId:
              Ref: mainBackendApi
mainBackendApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: !Ref Stage
      EndpointConfiguration:
        Type: EDGE
      Domain:
        DomainName: !Sub
            - <hidden>
            - apiSubDomain: …
Run Code Online (Sandbox Code Playgroud)

geolocation amazon-web-services aws-api-gateway aws-sam-cli aws-sam

5
推荐指数
0
解决办法
638
查看次数

redux-saga 中的重试功能

在我的应用程序中我有以下代码

componentWillUpdate(nextProps) {
  if(nextProps.posts.request.status === 'failed') {
    let timer = null;

    timer = setTimeout(() => {
      if(this.props.posts.request.timeOut == 1) {
        clearTimeout(timer);
        this.props.fetchData({
          page: this.props.posts.request.page
        });
      } else {
        this.props.decreaseTimeOut();
      }
    }, 1000);
  }
}
Run Code Online (Sandbox Code Playgroud)

它的作用是,当 API 请求遇到错误,可能是因为没有互联网连接(就像 facebook 的聊天方式一样),或者后端出现错误时,它会在五秒后重试,但setTimeout需要每隔一秒设置一次以更新存储的一部分,即行this.props.decreaseTimeOut();,但如果计数器已用完,五秒过去了,则将if block运行并重新分派fetchData action.

它工作得很好,我对它没有任何问题,至少在功能方面,但在代码设计方面,我知道它是一个side-effect并且不应该在我的反应组件中处理,因为我使用的是 redux- saga (但我是 redux-saga 的新手,我今天才学会),我想将该功能转换为 saga,我不太清楚如何做到这一点,这是我fetchData saga的道路。

import {
  take,
  call,
  put
} from 'redux-saga/effects';

import axios from 'axios';

export default function* fetchData() {
  while(true) { …
Run Code Online (Sandbox Code Playgroud)

reactjs redux redux-saga react-redux

4
推荐指数
1
解决办法
6836
查看次数