-
Notifications
You must be signed in to change notification settings - Fork 3
/
lambda.js
43 lines (35 loc) · 1.21 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
const path = require('path')
const serverless = require('serverless-http');
const minify = require('html-minifier').minify;
const { app } = require("./dist/angular-lambda-ssr/serverless/main");
const handle = serverless(app, {
provider: 'aws',
type: 'lambda-edge-origin-request'
});
const handler = async (event, context, callback) => {
const request = event.Records[0].cf.request;
if ((!path.extname(request.uri)) || (request.uri === '/index.html')) {
const response = await handle(event, context);
let minified = minify(response.body, {
caseSensitive: true,
collapseWhitespace: true,
preserveLineBreaks: true,
removeAttributeQuotes: true,
removeComments: true
});
console.log('response: ', response)
callback(null, {
status: response.status,
statusDescription: response.statusDescription,
headers: {
...response.headers,
},
body: minified,
bodyEncoding: response.bodyEncoding
});
} else {
console.log(`${request.uri} directly served from S3`)
return request;
}
}
exports.handler = handler;