-
Notifications
You must be signed in to change notification settings - Fork 1
/
handler.js
41 lines (38 loc) · 1.27 KB
/
handler.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
const fs = require('fs')
const path = require('path')
const files = {
'/public/index.css': {
content: fs.readFileSync(path.join(__dirname, 'public', 'index.css'), 'utf8'),
type: 'text/css'
},
'/public/main.js': {
content: fs.readFileSync(path.join(__dirname, 'public', 'main.js'), 'utf8'),
type: 'text/javascript'
},
'/': {
content: fs.readFileSync(path.join(__dirname, 'index.html'), 'utf8'),
type: 'text/html'
}
}
/**
*
* Event doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-input-format
* @param {Object} event - API Gateway Lambda Proxy Input Format
*
* Context doc: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html
* @param {Object} context
*
* Return doc: https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html
* @returns {Object} object - API Gateway Lambda Proxy Output Format
*
*/
exports.lambdaHandler = async (event, context) => {
// This will either be /, /public/index.css, or /public/main.js
const requestPath = event.path
const { content, type } = files[requestPath]
return {
headers: { 'content-type': type },
statusCode: 200,
body: content
}
}