[READ-ONLY] Mirror of https://github.com/kristianbinau/hf3-embedded2-webserver.
0

Configure Feed

Select the types of activity you want to include in your feed.

Add temp endpoint

Kristian Binau (Sep 22, 2021, 9:07 AM +0200) 801bfc12 13aed085

+16 -2
+16 -2
main.ts
··· 4 4 HttpResponse, 5 5 RequestMethod, 6 6 } from "https://deno.land/x/dragon@v1.1.6/lib/mod.ts"; 7 + import { Client } from "https://deno.land/x/mysql/mod.ts"; 8 + 9 + const client = await new Client().connect({ 10 + hostname: "127.0.0.1", 11 + username: "root", 12 + password: "root", 13 + db: "hf3-embedded-webserver-test", 14 + }); 7 15 8 16 const app = new Application(); 9 17 ··· 17 25 }, 18 26 ); 19 27 20 - r.withPath("/demo") 28 + r.withPath(/temp\/(?<temp>[0-9]+\.?[0-9]*|\.[0-9]+)/u).withMethods(RequestMethod.GET) 21 29 .handleFunc( 22 30 async function (Request: HttpRequest, ResponseWriter: HttpResponse) { 23 - ResponseWriter.end("Hello Dragon Demo"); 31 + const { temp: temperature } = Request.params(); 32 + const temp = temperature as unknown as number 33 + 34 + let result = await client.execute(`INSERT INTO data(data_name, value) values(?,?)`, [ 35 + "temp", 36 + 1000 * temp, 37 + ]); 24 38 }, 25 39 ); 26 40