Skip to content

Commit

Permalink
fix: /user/ => /user (#941)
Browse files Browse the repository at this point in the history
* fix: /user/ => /user

* fix: serverless app init context

* fix: serverless-app files
  • Loading branch information
echosoar authored Mar 24, 2021
1 parent fb6b3e0 commit 6883400
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 5 deletions.
5 changes: 2 additions & 3 deletions packages-serverless/serverless-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
"node": ">= 10"
},
"files": [
"plugin.json",
"dist",
"src"
"dist/**/*.js",
"dist/**/*.d.ts"
],
"scripts": {
"build": "midway-bin build -c",
Expand Down
2 changes: 1 addition & 1 deletion packages-serverless/serverless-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class Framework
framework: Framework,
layers: layers,
starter: require(starterName),
initializeContext: undefined,
initializeContext: this.configurationOptions?.initContext,
});
this.innerFramework = startResult.framework;
this.runtime = startResult.runtime;
Expand Down
3 changes: 3 additions & 0 deletions packages-serverless/serverless-app/src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export const start2 = async options => {
});
const runtime = await start({
layers: layers,
getApp: () => {
return starterInstance && starterInstance.getApplication();
},
initContext: initializeContext,
});
return {
Expand Down
5 changes: 4 additions & 1 deletion packages-serverless/serverless-app/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ export const analysisDecorator = async (cwd: string) => {
{
http: {
method: [].concat(func.requestMethod || 'get'),
path: (func.prefix + func.url).replace(/\/{1,}/g, '/'),
path: (func.prefix + (func.url === '/' ? '' : func.url)).replace(
/\/{1,}/g,
'/'
),
},
},
],
Expand Down
20 changes: 20 additions & 0 deletions packages-serverless/serverless-app/test/faas-v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ describe('test/faas-v2.test.ts', () => {
})
.catch(err => done(err));
});
it('http get controller', async done => {
request(app)
.get('/user')
.expect(200)
.then(response => {
assert(response.text === 'user');
done();
})
.catch(err => done(err));
});
it('http get controller params', async done => {
request(app)
.get('/user/midway')
.expect(200)
.then(response => {
assert(response.text === 'midway');
done();
})
.catch(err => done(err));
});
it('http post', async done => {
await request(app)
.post('/hello')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Provide, Controller, Get, Inject } from '@midwayjs/decorator';

@Provide()
@Controller('/user')
export class ControllerTestService {

@Inject()
ctx;


@Get('/')
async handler() {
return 'user'
}

@Get('/:test')
async test() {
return this.ctx.params.test;
}
}

0 comments on commit 6883400

Please sign in to comment.