Skip to content
Snippets Groups Projects
Commit 5fbd14e8 authored by Will Billingsley's avatar Will Billingsley
Browse files

Added /example/game route that allocates an id and redirects

parent 72503231
No related branches found
No related tags found
No related merge requests found
......@@ -25,3 +25,25 @@ export let respondWithJson = (req:Request, resp:Response) => {
}
})
}
const chars = "abcdefghijklmnopqrstuvwxyz0123456789"
export let game = (req:Request, resp:Response) => {
let id = req.query.id
let randomId = () => {
let code = ""
for (let i = 0; i < 8; i++) {
let n = Math.floor(Math.random() * chars.length)
code += chars.charAt(n)
}
return code
}
if (id !== undefined) {
resp.send("The id was " + id)
} else {
resp.redirect("/example/game?id=" + randomId())
}
}
\ No newline at end of file
......@@ -21,6 +21,7 @@ const port: string = process.env.PORT || "3000"
app.get('/', welcome.index)
app.get("/example/json", welcome.respondWithJson)
app.post("/example/json", welcome.receiveJsonPost)
app.get("/example/game", welcome.game)
/*
* Start the server
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment