diff --git a/docs/02-providers/aws/examples/web-serving-html/node/README.md b/docs/02-providers/aws/examples/web-serving-html/node/README.md index d00940403..8bbfe1b53 100644 --- a/docs/02-providers/aws/examples/web-serving-html/node/README.md +++ b/docs/02-providers/aws/examples/web-serving-html/node/README.md @@ -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 \ No newline at end of file +This is an example of serving vanilla HTML/CSS/JS through API Gateway \ No newline at end of file diff --git a/docs/02-providers/aws/examples/web-serving-html/node/handler.js b/docs/02-providers/aws/examples/web-serving-html/node/handler.js index 526c9a4a0..914016966 100644 --- a/docs/02-providers/aws/examples/web-serving-html/node/handler.js +++ b/docs/02-providers/aws/examples/web-serving-html/node/handler.js @@ -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 = `

Hey ${event.query.name}

` + dynamicHtml = `

Hey ${event.queryStringParameters.name}

`; + } else { + dynamicHtml = ''; } const html = ` @@ -19,10 +20,15 @@ module.exports.staticHtml = function (event, context, callback) {

Landing Page

${dynamicHtml} - `; - // 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); }; diff --git a/docs/02-providers/aws/examples/web-serving-html/node/serverless.yml b/docs/02-providers/aws/examples/web-serving-html/node/serverless.yml index 0419c46d0..097ced5e3 100644 --- a/docs/02-providers/aws/examples/web-serving-html/node/serverless.yml +++ b/docs/02-providers/aws/examples/web-serving-html/node/serverless.yml @@ -13,7 +13,3 @@ functions: - http: method: get path: landing-page - response: - headers: - Content-Type: "'text/html'" - template: $input.path('$') # return my html