Мы используем воспламеняем шаблон и apisuace для моего приложения.Существует странная проблема, когда некоторые из API-интерфейсов POST многократно подключаются к внутреннему серверу, который заглушает сервер и отключает сервер.Кто-нибудь сталкивался с этой проблемой?
Бэкэнд-сервер получает более 500 одновременных запросов в секунду.И это поведение прерывистое.
indexsaga.js
import { takeLatest, takeEvery } from "redux-saga/effects";
import API from "../Services/Api";
import FixtureAPI from "../Services/FixtureApi";
/* ------------- Types ------------- */
import { LoginTypes } from "../Redux/LoginRedux";
/* ------------- Sagas ------------- */
import {
loginWithOther,
} from "./LoginSaga";
/* ------------- API ------------- */
// The API we use is only used from Sagas, so we create it here and pass along
// to the sagas which need it.
const api = DebugConfig.useFixtures ? FixtureAPI : API.create();
/* ------------- Connect Types To Sagas ------------- */
export default function* root() {
yield [// some sagas receive extra parameters in addition to an action
takeLatest(LoginTypes.USER_REQUEST, loginWithOther, api),
];
}
LoginSaga.js
import { call, put, all, fork, select } from "redux-saga/effects";
import LoginActions from "../Redux/LoginRedux";
export function* loginWithOther(api, action) {
const { email, password, navigation } = action;
let payload = {
user_id: email,
password: password,
};
const response = yield call(api.loginWithEmail, payload);
if (response.ok) {
yield put(LoginActions.userSuccess(response));
} else {
yield put(LoginActions.userFailure());
}
} else {
yield put(LoginActions.userFailure());
}
}
Loginredux.js
import { createReducer, createActions } from 'reduxsauce'
import Immutable from 'seamless-immutable'
/* ------------- Types and Action Creators ------------- */
const { Types, Creators } = createActions({
userRequest: ['email', 'password'],
userSuccess: ['data'],
userFailure: null
})
export const LoginTypes = Types
export default Creators
/* ------------- Initial State ------------- */
export const INITIAL_STATE = Immutable({
fetching: false,
login_error: false,
data:null
})
/* ------------- Reducers ------------- */
export const request = (state, action) => {
return state.merge({ fetching: true, login_error: false })
}
export const success = (state, action) => {
const { data } = action
return state.merge({
fetching: false,
login_error: false,
data: data
})
}
export const userFailure = (state) =>
state.merge({ fetching: false, login_error: true })
/* ------------- Hookup Reducers To Types ------------- */
export const reducer = createReducer(INITIAL_STATE, {
[Types.USER_REQUEST]: request,
[Types.USER_SUCCESS]: success,
[Types.USER_FAILURE]: userFailure
})
Api.js
// a library to wrap and simplify api calls
import apisauce from "apisauce";
const create = (baseURL = Config.API_URL) => {
// ------
// STEP 1
// ------
//
// Create and configure an apisauce-based api object.
//
const api = apisauce.create({
// base URL is read from the "constructor"
baseURL,
// here are some default headers
headers: {
"Cache-Control": "no-cache",
"Transfer-Encoding": "chunked"
// 'Content-Encoding': 'gzip'
},
// 10 second timeout...
timeout: 20000
});
const URL_STRINGS = {
LOGIN_WITH_OTHER_EMAIL: "/api/v1/login/email",
}
const loginWithEmail = obj => {
return api.post(URL_STRINGS.LOGIN_WITH_OTHER_EMAIL, obj);
};
return {
loginWithEmail,
}
};
// let's return back our create method as the default.
export default {
create
};
LoginScreen.js
import React, { Component } from 'react'
import LoginActions from '../Redux/LoginRedux'
class LoginScreen extends Component {
render(){
<View>
<Text>Login</Text>
</View>
}
onLoginClick(){
this.props.loginWithEmail("exampleemail@example.com","123456")
Ï
}
}
const mapStateToProps = (state) => {
return {
}
}
const mapDispatchToProps = (dispatch) => {
return {
loginWithEmail: (email, password) =>
dispatch(LoginActions.userRequest(email, password))
}
}
export default connect(mapStateToProps, mapDispatchToProps)(LoginScreen)