pihentagy
pihentagy
DDeno
Created by max on 4/23/2024 in #help
With Deno.serveHttp marked as deprecated is there a way to run an HTTP server off of a Deno.Conn?
I also have this usecase, when I'm requesting user consent for accessing google account. So were there any solutions to a one-off serving? My code btw:
async function getCodeFromServing(port = 3000) {
console.log(`Waiting for a request on port ${port}`);
const conn = await Deno.listen({ port }).accept();

const requestEvent = await Deno.serveHttp(conn).nextRequest();
if (!requestEvent) throw new Error("Oh no, connetion closed");

const code = new URL(requestEvent.request.url).searchParams.get("code");

await requestEvent.respondWith(new Response("hello", { status: 200 }));
return code;
}
async function getCodeFromServing(port = 3000) {
console.log(`Waiting for a request on port ${port}`);
const conn = await Deno.listen({ port }).accept();

const requestEvent = await Deno.serveHttp(conn).nextRequest();
if (!requestEvent) throw new Error("Oh no, connetion closed");

const code = new URL(requestEvent.request.url).searchParams.get("code");

await requestEvent.respondWith(new Response("hello", { status: 200 }));
return code;
}
I modified it, but needs an extra setTimeout for server.shutdown, of throws an error
async function getCodeFromServing(port = 3000) {
let code: string | null = null;
const server = Deno.serve({ port }, (req) => {
code = new URL(req.url).searchParams.get("code");
console.info(`Got code ${code}\nAbout to shut down the server on port ${port}`)
server.shutdown(); // FIXME needs to be setTimeout(()=>server.shutdown()) to work
return new Response("Thanks for stopping by");
});

await server.finished;
return code;
}
async function getCodeFromServing(port = 3000) {
let code: string | null = null;
const server = Deno.serve({ port }, (req) => {
code = new URL(req.url).searchParams.get("code");
console.info(`Got code ${code}\nAbout to shut down the server on port ${port}`)
server.shutdown(); // FIXME needs to be setTimeout(()=>server.shutdown()) to work
return new Response("Thanks for stopping by");
});

await server.finished;
return code;
}
About to shut down the server on port 3000
error: Uncaught (in promise) Interrupted: operation canceled
About to shut down the server on port 3000
error: Uncaught (in promise) Interrupted: operation canceled
8 replies
DDeno
Created by pihentagy on 1/2/2024 in #help
get hours & minutes in a specific timezone
Thanks, seems to work:
> import * as datefns from 'npm:date-fns@2.30.0'
undefined
> import * as datefnstz from 'npm:date-fns-tz'
undefined
> const d= new Date()
undefined
> const zonedDateLA = datefnstz.utcToZonedTime(d, 'America/Los_Angeles')
undefined
> const zonedDateBud = datefnstz.utcToZonedTime(d, 'Europe/Budapest')
undefined
> [zonedDateBud.getHours(), zonedDateLA.getHours()]
[ 9, 0 ]
>
> import * as datefns from 'npm:date-fns@2.30.0'
undefined
> import * as datefnstz from 'npm:date-fns-tz'
undefined
> const d= new Date()
undefined
> const zonedDateLA = datefnstz.utcToZonedTime(d, 'America/Los_Angeles')
undefined
> const zonedDateBud = datefnstz.utcToZonedTime(d, 'Europe/Budapest')
undefined
> [zonedDateBud.getHours(), zonedDateLA.getHours()]
[ 9, 0 ]
>
6 replies
DDeno
Created by pihentagy on 1/2/2024 in #help
get hours & minutes in a specific timezone
But getHour and others retuns values in local time. But how can I change (set) that locale? Setting the TZ env var seems not to affect that.
6 replies
DDeno
Created by pihentagy on 10/26/2023 in #help
kv store key granuality
I mean where there are multiple value to a user
7 replies
DDeno
Created by pihentagy on 10/26/2023 in #help
kv store key granuality
Ok, but in that case the upload logic would be a bit more complicated: gettint the whole user object, doing an updated user object, and setting it instead of just boom, addimg a new sub object
7 replies