mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
migrate to lambda-proxy integration type
This commit is contained in:
parent
e43d3abcc4
commit
ff990f3aa1
@ -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
|
||||
@ -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);
|
||||
};
|
||||
|
||||
@ -13,7 +13,3 @@ functions:
|
||||
- http:
|
||||
method: get
|
||||
path: landing-page
|
||||
response:
|
||||
headers:
|
||||
Content-Type: "'text/html'"
|
||||
template: $input.path('$') # return my html
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user