Transform AWS event payload into event for DataSource.ServerRequest JSON.

This commit is contained in:
Dillon Kearns 2021-12-16 12:05:59 -08:00
parent a9ebd8559a
commit 35c5be1ee0
3 changed files with 25 additions and 3 deletions

View File

@ -39,7 +39,7 @@ async function render(event, context) {
require(compiledElmPath),
mode,
event.path,
event,
reqToJson(event),
addWatcher
);
@ -76,3 +76,24 @@ async function render(event, context) {
};
}
}
// * @param {import('aws-lambda').APIGatewayProxyEvent} event
/**
* @param {import('aws-lambda').APIGatewayProxyEvent} req
* @returns {{ method: string; hostname: string; query: string; headers: Object; host: string; pathname: string; port: string; protocol: string; rawUrl: string; }}
*/
function reqToJson(req) {
return {
method: req.httpMethod,
hostname: "TODO",
// query: req.queryStringParameters, //url.search ? url.search.substring(1) : "",
query: "", //url.search ? url.search.substring(1) : "",
headers: req.headers,
host: url.host,
pathname: req.path,
port: null, // TODO
protocol: "https", // TODO
rawUrl: "", // TODO
};
}

View File

@ -252,6 +252,7 @@ async function start(options) {
* @param {string} pathname
* @param {((value: any) => any) | null | undefined} onOk
* @param {((reason: any) => PromiseLike<never>) | null | undefined} onErr
* @param {{ method: string; hostname: string; query: string; headers: Object; host: string; pathname: string; port: string; protocol: string; rawUrl: string; }} serverRequest
*/
function runRenderThread(serverRequest, pathname, onOk, onErr) {
let cleanUpThread = () => {};

View File

@ -24,7 +24,7 @@ module.exports =
* @param {string} basePath
* @param {Object} elmModule
* @param {string} path
* @param {import('aws-lambda').APIGatewayProxyEvent} request
* @param {{ method: string; hostname: string; query: string; headers: Object; host: string; pathname: string; port: string; protocol: string; rawUrl: string; }} request
* @param {(pattern: string) => void} addDataSourceWatcher
* @returns
*/
@ -59,7 +59,7 @@ module.exports =
* @param {Object} elmModule
* @param {string} pagePath
* @param {string} mode
* @param {import('aws-lambda').APIGatewayProxyEvent} request
* @param {{ method: string; hostname: string; query: string; headers: Object; host: string; pathname: string; port: string; protocol: string; rawUrl: string; }} request
* @param {(pattern: string) => void} addDataSourceWatcher
* @returns {Promise<({is404: boolean} & ( { kind: 'json'; contentJson: string} | { kind: 'html'; htmlString: string } | { kind: 'api-response'; body: string; }) )>}
*/