-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathlambda.js
54 lines (47 loc) · 1.41 KB
/
lambda.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict';
process.env.NODE_ENV = 'production';
const serverlessHttp = require('serverless-http');
const config = require('hops-config');
const { trimSlashes } = require('pathifist');
const app = require('hops-express').configure(config).createServer('serve');
const awsConfig = require('./lib/aws-config')(config);
const shouldIncludeStageInRequest =
trimSlashes(config.basePath).indexOf(awsConfig.stageName) === 0 &&
trimSlashes(config.assetPath).indexOf(awsConfig.stageName) === 0;
// NOTE: If you get ERR_CONTENT_DECODING_FAILED in your browser, this is likely
// due to a compressed response (e.g. gzip) which has not been handled correctly
// by serverless-http and/or API Gateway. Add the necessary MIME types to
// binaryMimeTypes below, then redeploy.
const binaryMimeTypes = [
'application/javascript',
'application/json',
'application/octet-stream',
'application/xml',
'font/eot',
'font/opentype',
'font/otf',
'font/woff',
'font/woff2',
'image/jpeg',
'image/png',
'image/svg+xml',
'image/x-icon',
'image/webp',
'text/comma-separated-values',
'text/css',
'text/csv',
'text/html',
'text/javascript',
'text/plain',
'text/text',
'text/xml',
];
exports.handler = serverlessHttp(app, {
binary: binaryMimeTypes,
request: function (request, context) {
if (shouldIncludeStageInRequest) {
request.url = context.requestContext.path;
}
return request;
},
});