migrate to lambda-proxy integration type

This commit is contained in:
Maciej Winnicki 2016-10-13 12:36:38 +02:00
parent e43d3abcc4
commit ff990f3aa1
No known key found for this signature in database
GPG Key ID: 950BD3CA7EDF6008
3 changed files with 17 additions and 15 deletions

View File

@ -4,6 +4,6 @@ menuText: Serving Static HTML
layout: Doc
-->
# Serving Static HTML with NodeJS + APIGateway
# Serving Static HTML with NodeJS + API Gateway
This is an example of serving vanilla HTML/CSS/JS through API-gateway
This is an example of serving vanilla HTML/CSS/JS through API Gateway

View File

@ -2,12 +2,13 @@
// Your function handler
module.exports.staticHtml = function (event, context, callback) {
var defaultEmptyHTML = ''
var dynamicHtml = defaultEmptyHTML
let dynamicHtml;
/* check for GET params and use if available */
if(event.query && event.query.name) {
if (event.queryStringParameters && event.queryStringParameters.name) {
// yourendpoint.com/dev/landing-page?name=bob
dynamicHtml = `<p>Hey ${event.query.name}</p>`
dynamicHtml = `<p>Hey ${event.queryStringParameters.name}</p>`;
} else {
dynamicHtml = '';
}
const html = `
@ -19,10 +20,15 @@ module.exports.staticHtml = function (event, context, callback) {
<h1>Landing Page</h1>
${dynamicHtml}
</body>
<script>
console.log('Hi there!')
</script>
</html>`;
// callback will send message object back
callback(null, html);
const response = {
statusCode: 200,
headers: {
'Content-Type': 'text/html',
},
body: html,
};
// callback will send HTML back
callback(null, response);
};

View File

@ -13,7 +13,3 @@ functions:
- http:
method: get
path: landing-page
response:
headers:
Content-Type: "'text/html'"
template: $input.path('$') # return my html