Skip to content

Commit

Permalink
use secret for suffix (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
cultpodcasts authored Oct 5, 2024
1 parent d42754e commit e7a2beb
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Env = {
secureEpisodesOutgoingEndpoint: URL;
secureEpisodePublishEndpoint: URL;
secureAdminSearchIndexerEndpoint: URL;
stagingHostSuffix: string;
}

const allowedOrigins: Array<string> = [
Expand All @@ -37,9 +38,7 @@ const allowedOrigins: Array<string> = [
"https://localhost:8790"
];

const stagingHostSuffix = ".website-83e.pages.dev";

function getOrigin(origin: string | null | undefined) {
function getOrigin(origin: string | null | undefined, stagingHostSuffix: string) {
if (origin == null || (allowedOrigins.indexOf(origin.toLowerCase()) == -1 && !origin.endsWith(stagingHostSuffix))) {
origin = allowedOrigins[0];
}
Expand Down Expand Up @@ -73,7 +72,7 @@ const auth0Middleware = createMiddleware<{

app.use('/*', cors({
origin: (origin, c) => {
return getOrigin(origin);
return getOrigin(origin, c.env.stagingHostSuffix);
},
allowHeaders: ['content-type', 'authorization'],
allowMethods: ['GET', 'HEAD', 'POST', 'OPTIONS', 'PUT'],
Expand Down Expand Up @@ -889,7 +888,6 @@ app.post("/searchindex/run", auth0Middleware, async (c) => {
const authorisation: string = c.req.header("Authorization")!;
console.log(`Using auth header '${authorisation.slice(0, 20)}..'`);
let resp: Response | undefined;
console.log(c.env.secureAdminSearchIndexerEndpoint.toString())
resp = await fetch(c.env.secureAdminSearchIndexerEndpoint, {
headers: {
'Accept': "*/*",
Expand Down

0 comments on commit e7a2beb

Please sign in to comment.