This file contains 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
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