我有一个React应用程序,试图从AWS访问无服务器。但是我有下面的错误
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://www.test.com' is therefore not allowed access. The response had HTTP status code 502.
Run Code Online (Sandbox Code Playgroud)
端点网址为https://key.execute-api.ap-southeast-2.amazonaws.com/dev/samplefunction
在serverless.yml上的设置是
login:
handler: login.login
events:
- http:
path: login
method: post
cors:
origin: 'https://admin.differentdomain.com'
headers:
- MY_CUSTOM_HEADER
- Content-Type
- X-Amz-Date
- Authorization
- X-Api-Key
- X-Amz-Security-Token
Run Code Online (Sandbox Code Playgroud)
我还有其他地方需要进行CORS配置吗?
当我尝试执行以下代码时,我的反应本机应用程序出现错误
react-native run-android --variant=release
Run Code Online (Sandbox Code Playgroud)
Starting a Gradle Daemon (subsequent builds will be faster)
> Configure project :react-native-firebase
react-native-firebase: using React Native prebuilt binary from /Users/sanglee/Documents/react-native-firebase-starter/node_modules/react-native/android
FAILURE: Build failed with an exception.
* What went wrong:
Task 'installDebug' not found in project ':app'.
Run Code Online (Sandbox Code Playgroud)
我从react-native-firebase下载了react-native应用程序,甚至无法使用android进行测试。
我正在为 React 项目编写单元测试代码。我正在尝试测试一个功能
//function aa
export const login = (values) => async => (dispatch) => {
let bodyFormData = new FormData();
bodyFormData.append('username', values.login);
bodyFormData.append('password', values.password);
return await axios({
method: 'post',
url: url,
data: bodyFormData
}
}
//aa test
it("Login Action", async () => {
afterEach(() => {
store.clearActions();
});
const values = {
login: "aaaaa",
password: "bbbbb"
};
const expectedResult = { type: "LOGIN_PASS" };
const result = await store.dispatch(login(values));
expect(result).toEqual(expectedResult);
});
Run Code Online (Sandbox Code Playgroud)
在浏览器中,这工作正常。但是在测试时我得到以下错误
参考错误:未定义 FormData
我尝试使用此模块但没有运气... https://www.npmjs.com/package/form-data
我不想只测试 axios,我需要测试完整的功能。