Skip to content

Commit

Permalink
Get the self URL from environment to allow easier dev and deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
rpavlik committed Jan 25, 2023
1 parent 2b196e2 commit a41acaf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/server/ghstrategy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { Strategy as GitHubStrategy } from 'passport-github2';
import { GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET } from './secrets';
import { GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET, SELF_URL } from './secrets';
import GHAuthUser from '../shared/GitHubAuthenticatedUser';
import { addKnownUser, fromGHAU } from './User';
const callbackURL =
process.env.NODE_ENV === 'production'
? 'http://tcq.app/auth/github/callback'
: 'http://127.0.0.1:3000/auth/github/callback';

var makeCallbackBase = function() {
if (process.env.NODE_ENV === 'production') {
return SELF_URL;
}
if (SELF_URL) {
return SELF_URL;
}
return 'http://127.0.0.1:3000';
};
const callbackURL = makeCallbackBase() + '/auth/github/callback';

export default new GitHubStrategy(
{
Expand All @@ -14,7 +21,7 @@ export default new GitHubStrategy(
callbackURL,
scope: ['user:email'],
},
function (accessToken: string, refreshToken: string, profile: any, cb: any) {
function(accessToken: string, refreshToken: string, profile: any, cb: any) {
let user: GHAuthUser = {
name: profile.displayName,
ghUsername: profile.username!, // why might this be undefined?
Expand Down
8 changes: 8 additions & 0 deletions src/server/secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export const GITHUB_CLIENT_SECRET = prod
export const GITHUB_CLIENT_ID = prod ? process.env['TCQ_GH_ID']! : process.env['TCQ_LOCAL_GH_ID']!;
export const SESSION_SECRET = process.env['TCQ_SESSION_SECRET']!;
export const CDB_SECRET = process.env['TCQ_CDB_SECRET']!;

export const SELF_URL = prod ? process.env['TCQ_SELF_URL']! : process.env['TCQ_LOCAL_SELF_URL']!;

export const AI_IKEY = process.env['TCQ_AI_IKEY'];

if (!GITHUB_CLIENT_SECRET) {
Expand All @@ -30,6 +33,11 @@ if (!CDB_SECRET) {
process.exit(1);
}

if (prod && !SELF_URL) {
log.fatal('ERROR\tNo self URL set. Set TCQ_SELF_URL or TCQ_LOCAL_SELF_URL.');
process.exit(1);
}

if (!AI_IKEY) {
log.fatal('ERROR\tNo Application Insights Instrumentation Key. Set TCQ_AI_IKEY.');
process.exit(1);
Expand Down

0 comments on commit a41acaf

Please sign in to comment.