Skip to content

Commit

Permalink
fix: application return 301 and buffer case (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 committed Aug 11, 2020
1 parent 6160093 commit a31c022
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/egg-layer/framework/config/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ exports.logger = {
exports.rundir = os.tmpdir();

exports.static = {
dir: os.tmpdir(),
buffer: true,
};
4 changes: 0 additions & 4 deletions packages/egg-layer/framework/config/plugin.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
'use strict';

exports.onerror = false;
exports.i18n = false;
exports.watcher = false;
exports.multipart = false;
exports.security = false;
exports.development = false;
exports.logrotator = false;
exports.schedule = false;
exports.static = false;
1 change: 1 addition & 0 deletions packages/egg-layer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module.exports = engine => {
},
(error, response, body) => {
context.res = response;
context.status = response.statusCode;
if (error) {
reject(error);
}
Expand Down
6 changes: 6 additions & 0 deletions packages/egg-layer/test/fixtures/eaas-fc/app/public/news.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
body,
html {
font-family: Verdana;
font-size: 13px;
height: 100%
}
1 change: 1 addition & 0 deletions packages/egg-layer/test/fixtures/eaas-fc/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
module.exports = app => {
const { router, controller } = app;
router.redirect('/', '/get');
router.get('/get', controller.home.getMethod);
router.get('/get/query', controller.home.getQueryMethod);
router.post('/post', controller.home.postMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = appInfo => {
* built-in config
* @type {Egg.EggAppConfig}
**/
const config = exports = {};
const config = (exports = {});

// use for cookie sign key, should change to your own and keep security
config.keys = appInfo.name + '_1574154057813_8098';
Expand All @@ -23,6 +23,12 @@ module.exports = appInfo => {
// myAppName: 'egg',
};

config.security = {
csrf: {
enable: false,
},
};

return {
...config,
...userConfig,
Expand Down
6 changes: 6 additions & 0 deletions packages/egg-layer/test/fixtures/eaas-scf/app/public/news.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
body,
html {
font-family: Verdana;
font-size: 13px;
height: 100%
}
1 change: 1 addition & 0 deletions packages/egg-layer/test/fixtures/eaas-scf/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
module.exports = app => {
const { router, controller } = app;
router.redirect('/', '/get');
router.get('/get', controller.home.getMethod);
router.get('/get/query', controller.home.getQueryMethod);
router.post('/post', controller.home.postMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = appInfo => {
* built-in config
* @type {Egg.EggAppConfig}
**/
const config = exports = {};
const config = (exports = {});

// use for cookie sign key, should change to your own and keep security
config.keys = appInfo.name + '_1574154057813_8098';
Expand All @@ -23,6 +23,12 @@ module.exports = appInfo => {
// myAppName: 'egg',
};

config.security = {
csrf: {
enable: false,
},
};

return {
...config,
...userConfig,
Expand Down
45 changes: 45 additions & 0 deletions packages/egg-layer/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ describe('/test/index.test.ts', () => {
.expect(/{"body":{"b":1}}/)
.expect(200, done);
});

it('should test static file', done => {
request(app)
.get('/public/news.css')
.expect('Content-Type', 'text/css; charset=utf-8')
.expect(/font-size/)
.expect(200, done);
});

it('should test redirect router', done => {
request(app)
.get('/')
.expect('Content-Type', 'text/html; charset=utf-8')
.expect(301, done);
});
});

describe('FC test with api gateway', () => {
Expand Down Expand Up @@ -126,6 +141,21 @@ describe('/test/index.test.ts', () => {
.expect(/{"body":{"b":1}}/)
.expect(200, done);
});

it('should test static file', done => {
request(app)
.get('/public/news.css')
.expect('Content-Type', 'text/css; charset=utf-8')
.expect(/font-size/)
.expect(200, done);
});

it('should test redirect router', done => {
request(app)
.get('/')
.expect('Content-Type', 'text/html; charset=utf-8')
.expect(301, done);
});
});

describe('SCF test with api gateway', () => {
Expand Down Expand Up @@ -186,5 +216,20 @@ describe('/test/index.test.ts', () => {
.expect(/{"body":{"b":1}}/)
.expect(200, done);
});

it('should test static file', done => {
request(app)
.get('/public/news.css')
.expect('Content-Type', 'text/css; charset=utf-8')
.expect(/font-size/)
.expect(200, done);
});

it('should test redirect router', done => {
request(app)
.get('/')
.expect('Content-Type', 'text/html; charset=utf-8')
.expect(301, done);
});
});
});
1 change: 1 addition & 0 deletions packages/express-layer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = engine => {
},
(error, response, body) => {
context.res = response;
context.status = response.statusCode;
if (error) {
reject(error);
}
Expand Down
1 change: 1 addition & 0 deletions packages/koa-layer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = engine => {
},
(error, response, body) => {
context.res = response;
context.status = response.statusCode;
if (error) {
reject(error);
}
Expand Down
10 changes: 8 additions & 2 deletions packages/serverless-fc-starter/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,14 @@ export class FCRuntime extends ServerlessLightRuntime {
}
}

if (res.setStatusCode) {
res.setStatusCode(ctx.status);
if (res.statusCode !== ctx.status) {
if (res.setStatusCode) {
res.setStatusCode(ctx.status);
}

if (res.statusCode) {
res.statusCode = ctx.status;
}
}

if (res.send) {
Expand Down

0 comments on commit a31c022

Please sign in to comment.