我正在尝试使用 SAM 本地 CLI 在本地测试我的 lambda 函数。我使用以下命令启动 API:
sam local start-api --template ./sam-template.yml --host 0.0.0.0 --port 4001
Run Code Online (Sandbox Code Playgroud)
但是,每次调用 API 时,lambda 调用都会花费大量时间(4-5 秒),我假设每次调用函数时都会启动 docker 容器。
有解决方法吗?
我创建了一个授权服务,如下所示
@SpringBootApplication
@EnableAuthorizationServer
public class AuthorizationApplication {
...
}
Run Code Online (Sandbox Code Playgroud)
有了这个application.properties.
server.port=9000
security.oauth2.client.client-id=monederobingo
security.oauth2.client.client-secret=monederobingosecret
security.oauth2.client.authorized-grant-types=authorization_code,refresh_token,password,client_credentials
security.oauth2.client.scope=company,client
Run Code Online (Sandbox Code Playgroud)
然后,在一个单独的Spring启动项目中,我创建了一个资源服务器.
@SpringBootApplication
@EnableResourceServer
public class App {
...
}
Run Code Online (Sandbox Code Playgroud)
有了这个application.properties.
server.port=9090
spring.application.name=app
security.oauth2.resource.user-info-uri=http://localhost:9000/user
Run Code Online (Sandbox Code Playgroud)
现在,如果我localhost:9090/api使用由授权服务检索的相应令牌发送此类请求,一切正常.
但是,我不想在发送请求时发送此令牌localhost:9090/login.
为此我在Resource server spring boot app中创建了这个类.
@Configuration
public class SpringConfig extends WebSecurityConfigurerAdapter {
@Override protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.antMatchers("/login")
.permitAll()
.antMatchers("/api/**")
.authenticated();
}
}
Run Code Online (Sandbox Code Playgroud)
现在我不需要发送任何令牌来发送请求/login.
但是,我现在正在/api使用有效令牌发送请求时发出以下消息.
{
"timestamp": 1496027102659,
"status": 403,
"error": "Forbidden",
"message": …Run Code Online (Sandbox Code Playgroud) 我有一个使用spyOn方法的单元测试jest.
import React from 'react';
import expect from 'jest-matchers';
import PointsAwardingPage from '../PointsAwardingPage';
import PointsAwardingForm from '../children/PointsAwardingForm';
import { shallow } from 'enzyme';
it("should call change method in form", () => {
// given
spyOn(PointsAwardingPage.prototype, 'change').and.callThrough();
const form = shallow(<PointsAwardingPage />).find('PointsAwardingForm');
// when
form.props().onChange();
// then
expect(PointsAwardingPage.prototype.change).toHaveBeenCalled();
});
Run Code Online (Sandbox Code Playgroud)
一切都很好.但是,我看到eslint有关spyOn函数调用的以下错误消息.
spyOn is not defined (no-undef).
import我可以使用哪种语句来摆脱这个错误?
我正在使用fetch-mock来模拟对服务器的一些请求。这是所有请求的发出地:
import fetchMock from 'fetch-mock'
import initialState from 'src/initial-state'
if (process.env.NODE_ENV === 'development') {
fetchMock.post('/some/endpoint', initialState.entities.multichannelEngagement)
}
Run Code Online (Sandbox Code Playgroud)
但是,不仅此端点是模拟的,而且所有同构提取的请求
import 'isomorphic-fetch'
export function makeRequest(endpoint, config = {}) {
return window.fetch(endpoint, config)
.then(response => {
return response.json()
.then(json => ({ json, response }))
.catch(() => ({ response }))
})
.then(({ json, response }) => {
if (!response.ok) {
throw json ? json : new Error(response.statusText)
} else {
return json
}
})
.catch((e) => {
return Promise.reject(e)
})
Run Code Online (Sandbox Code Playgroud)
}
我的webpack.config.js如下:
import path …Run Code Online (Sandbox Code Playgroud) 我有一个request url接受重复查询字符串来发送数据的。格式为:
http://<rest_url>/resource?scheduledate=2018-02-25&scheduledate=2018-03-02
Run Code Online (Sandbox Code Playgroud)
这将检索两个日期之间的数据。现在的问题是如何发送查询字符串。我在用着requests。我的代码是
var options = {
url: rest_url ,
// this will not work since you cant have duplicate keys
qs:{
'scheduledDate':moment().add(-1,'days').format('YYYY-MM-DD'),
'scheduledDate':moment().add(1,'days').format('YYYY-MM-DD');
},
auth: {
'bearer': token[0]['access_token']
}
}
// **************** Rest Request to API *************************
request.get(options, function(error, response, body) {
if (!error && response.statusCode === 200) {
Run Code Online (Sandbox Code Playgroud)
现在如何发送重复的查询字符串?我尝试做
var yesterday = moment().add(-1,'days').format('YYYY-MM-DD');
var OneDayinFuture=moment().add(1,'days').format('YYYY-MM-DD');
var query_string =yesterday+ "&scheduledDate="+OneDayinFuture;
var options = {
url: rest_url ,
qs:{
'scheduledDate':query_string
},
auth: {
'bearer': token[0]['access_token'] …Run Code Online (Sandbox Code Playgroud) javascript ×2
aws-lambda ×1
aws-sam ×1
cold-start ×1
eslint ×1
fetch ×1
fetch-mock ×1
java ×1
jestjs ×1
mocking ×1
node.js ×1
reactjs ×1
spring-boot ×1
unit-testing ×1
webpack ×1