-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove AppConstants #5044
Remove AppConstants #5044
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
|
||
import { getToken } from "next-auth/jwt"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import AppConstants from "../../../../../appConstants"; | ||
|
||
import { getSubscriberByFxaUid } from "../../../../../db/tables/subscribers"; | ||
import { addSubscriberUnverifiedEmailHash } from "../../../../../db/tables/emailAddresses"; | ||
|
@@ -108,6 +107,6 @@ export async function POST(req: NextRequest) { | |
} | ||
} else { | ||
// Not Signed in, redirect to home | ||
return NextResponse.redirect(AppConstants.SERVER_URL, 301); | ||
return NextResponse.redirect(process.env.SERVER_URL ?? "/", 301); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious why you don't use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good question, and I was (still am) on the fence. My reasoning was as follows: It looks like |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ import { getToken } from "next-auth/jwt"; | |
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
import { logger } from "../../../../functions/server/logging"; | ||
import AppConstants from "../../../../../appConstants"; | ||
import { | ||
getSubscriberByFxaUid, | ||
deleteResolutionsWithEmail, | ||
|
@@ -50,7 +49,7 @@ export async function POST(req: NextRequest) { | |
existingEmail.email, | ||
); | ||
return NextResponse.redirect( | ||
AppConstants.SERVER_URL + "/user/settings", | ||
process.env.SERVER_URL + "/user/settings", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question re: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same reasoning as #5044 (comment) - in this case, if it's unset, it would fall back to redirecting to |
||
301, | ||
); | ||
} catch (e) { | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
if ( | ||
typeof process.env.NEXT_RUNTIME === "undefined" && | ||
typeof process.env.STORYBOOK === "undefined" | ||
) { | ||
// Next.js already loads env vars by itself, and dotenv-flow will throw an | ||
// error if loaded in that context (about `fs` not existing), so only load | ||
// it if we're not running in a Next.js-context (e.g. cron jobs): | ||
await import("dotenv-flow/config"); | ||
} | ||
|
||
export function getEnvVarsOrThrow<EnvVarNames extends string>( | ||
envVars: EnvVarNames[], | ||
): Record<EnvVarNames, string> { | ||
const envVarsRecord: Record<EnvVarNames, string> = {} as never; | ||
for (const varName of envVars) { | ||
const value = process.env[varName]; | ||
if (typeof value !== "string") { | ||
throw new Error( | ||
`Required environment variable was not set: [${varName}].`, | ||
); | ||
} | ||
envVarsRecord[varName] = value; | ||
} | ||
return envVarsRecord; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,19 +33,36 @@ | |
* | ||
*/ | ||
|
||
import AppConstants from "../../appConstants"; | ||
import * as HIBP from "../../utils/hibp"; | ||
|
||
type RemoteSettingsBreach = Pick< | ||
HIBP.HibpGetBreachesResponse[number], | ||
"Name" | "Domain" | "BreachDate" | "PwnCount" | "AddedDate" | "DataClasses" | ||
>; | ||
|
||
const FX_REMOTE_SETTINGS_WRITER_USER = | ||
process.env.FX_REMOTE_SETTINGS_WRITER_USER; | ||
const FX_REMOTE_SETTINGS_WRITER_PASS = | ||
process.env.FX_REMOTE_SETTINGS_WRITER_PASS; | ||
const FX_REMOTE_SETTINGS_WRITER_SERVER = | ||
process.env.FX_REMOTE_SETTINGS_WRITER_SERVER; | ||
|
||
if ( | ||
!FX_REMOTE_SETTINGS_WRITER_USER || | ||
!FX_REMOTE_SETTINGS_WRITER_PASS || | ||
!FX_REMOTE_SETTINGS_WRITER_SERVER | ||
) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like you could use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I was actually considering that too, but then I figured I'd have to wrap the entire file in a |
||
console.error( | ||
"updatebreaches requires FX_REMOTE_SETTINGS_WRITER_SERVER, FX_REMOTE_SETTINGS_WRITER_USER, FX_REMOTE_SETTINGS_WRITER_PASS.", | ||
); | ||
process.exit(1); | ||
} | ||
|
||
const BREACHES_COLLECTION = "fxmonitor-breaches"; | ||
const FX_RS_COLLECTION = `${AppConstants.FX_REMOTE_SETTINGS_WRITER_SERVER}/buckets/main-workspace/collections/${BREACHES_COLLECTION}`; | ||
const FX_RS_COLLECTION = `${FX_REMOTE_SETTINGS_WRITER_SERVER}/buckets/main-workspace/collections/${BREACHES_COLLECTION}`; | ||
const FX_RS_RECORDS = `${FX_RS_COLLECTION}/records`; | ||
const FX_RS_WRITER_USER = AppConstants.FX_REMOTE_SETTINGS_WRITER_USER; | ||
const FX_RS_WRITER_PASS = AppConstants.FX_REMOTE_SETTINGS_WRITER_PASS; | ||
const FX_RS_WRITER_USER = FX_REMOTE_SETTINGS_WRITER_USER; | ||
const FX_RS_WRITER_PASS = FX_REMOTE_SETTINGS_WRITER_PASS; | ||
|
||
async function whichBreachesAreNotInRemoteSettingsYet( | ||
breaches: HIBP.HibpGetBreachesResponse, | ||
|
@@ -90,17 +107,6 @@ async function requestReviewOnBreachesCollection() { | |
return response.json(); | ||
} | ||
|
||
if ( | ||
!AppConstants.FX_REMOTE_SETTINGS_WRITER_USER || | ||
!AppConstants.FX_REMOTE_SETTINGS_WRITER_PASS || | ||
!AppConstants.FX_REMOTE_SETTINGS_WRITER_SERVER | ||
) { | ||
console.error( | ||
"updatebreaches requires FX_REMOTE_SETTINGS_WRITER_SERVER, FX_REMOTE_SETTINGS_WRITER_USER, FX_REMOTE_SETTINGS_WRITER_PASS.", | ||
); | ||
process.exit(1); | ||
} | ||
|
||
(async () => { | ||
const allHibpBreaches = await HIBP.fetchHibpBreaches(); | ||
const verifiedSiteBreaches = allHibpBreaches.filter((breach) => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's pretty cool, nice idea. I didn't like how non-standard
AppConstants
was but I really like the behavior of throwing upfront.