Created
August 6, 2019 01:06
-
-
Save hugosenari/35631454fd5bfa10d5eef950cc8682ac to your computer and use it in GitHub Desktop.
Add Service Scope to Laconia example of use
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const laconia = require("@laconia/core"); | |
const api = require("@laconia/adapter-api").apigateway({ inputType: "body" }); | |
const AWS = require('aws-sdk'); | |
const instances = ({ requestContext: { connectionId, domainName, stage } }) => ({ | |
send: async payload => { | |
const client = new AWS.ApiGatewayManagementApi({ | |
apiVersion: '2018-11-29', | |
endpoint: `https://${domainName}/${stage}` | |
}); | |
return client.postToConnection({ | |
ConnectionI: connectionId, | |
Data: JSON.stringify(payload, null, 2) | |
}) | |
.promise(); | |
} | |
}); | |
const app = async ({ answer }, { send }) => { | |
if (answer) await send({ answer }); | |
return "success"; | |
}; | |
exports.handler = laconia(api(app)).register(instances, { scoped: true }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment