Skip to content

Commit

Permalink
Allow passing Discourse token as param (#2)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcus Weiner <mraerino@users.noreply.github.com>
  • Loading branch information
ansgarprause and mraerino committed Apr 16, 2023
1 parent a1260e0 commit 35604e5
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { serve } from "https://deno.land/std@0.177.0/http/server.ts";
import { Handler, serve } from "https://deno.land/std@0.177.0/http/server.ts";
import { z } from "https://deno.land/x/zod@v3.20.5/index.ts";
import ical, { ICalEventData } from "https://esm.sh/v108/ical-generator@3.6.1";
import {
Expand All @@ -8,11 +8,20 @@ import {

const discourseUrl = Deno.env.get("DISCOURSE_URL");

const handle = async () => {
let body;
const handle: Handler = async (request) => {
const eventsUrl = new URL("/discourse-post-event/events.json", discourseUrl);

const requestUrl = new URL(request.url);
const token = requestUrl.searchParams.get("token");

let body;
try {
const response = await fetch(eventsUrl);
const response = await fetch(
eventsUrl,
token
? { headers: { Cookie: `_t=${encodeURIComponent(token)}` } }
: undefined
);
if (!response.ok) {
console.error("Response status", response.status);
return new Response("Failed to fetch events", { status: 502 });
Expand Down

0 comments on commit 35604e5

Please sign in to comment.