Skip to content

Instantly share code, notes, and snippets.

@MarcoPolo
Created June 5, 2020 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcoPolo/72b581b0fe3f2b33f0b0e7ad23f78bca to your computer and use it in GitHub Desktop.
Save MarcoPolo/72b581b0fe3f2b33f0b0e7ad23f78bca to your computer and use it in GitHub Desktop.
import { Dice } from 'https://deno.land/x/dodecasaurus/mod.ts';
import { Node } from 'https://deno.land/x/router/mod.ts'
import {
APIGatewayProxyEvent,
APIGatewayProxyResult,
Context
} from "https://deno.land/x/lambda/mod.ts";
const root = new Node();
root.add("/roll/:nSided", (p: any) => {
const d = new Dice(parseInt(p.get('nSided')))
return d.roll()
});
root.add("/", (p: any) => {
return "Hello"
});
export default async function (
event: APIGatewayProxyEvent,
context: Context
): Promise<APIGatewayProxyResult> {
const path = '/' + (event.pathParameters?.proxy || '')
console.log("Path is", path)
const [handler, p] = root.find(path);
if (handler) {
return {
body: handler(p),
headers: { "content-type": "text/html;charset=utf8" },
statusCode: 200
};
}
return {
body: `Welcome to deno ${Deno.version.deno} 🦕 ${JSON.stringify(event)}`,
headers: { "content-type": "text/html;charset=utf8" },
statusCode: 200
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment