Skip to content

Commit

Permalink
docs(various): documenting required env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
xinbenlv committed May 3, 2021
1 parent 01940ad commit 1073af3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,21 @@ app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(require('express-status-monitor')());

console.assert(process.env.OPEN_GOLINKS_GA_ID, `OPEN_GOLINKS_GA_ID is not set`);
console.assert(process.env.MONGODB_URI, `MONGODB_URI is not set`);
console.assert(process.env.AUTH0_DOMAIN, `AUTH0_DOMAIN is not set`);
console.assert(process.env.AUTH0_CLIENT_ID, `AUTH0_CLIENT_ID is not set`);
console.assert(process.env.AUTH0_CLIENT_SECRET, `AUTH0_CLIENT_SECRET is not set`);
[
"OPEN_GOLINKS_GA_ID",
"OPEN_GOLINKS_SITE_NAME",
"OPEN_GOLINKS_SITE_HOST",
"MONGODB_URI",
"AUTH0_DOMAIN",
"AUTH0_CLIENT_ID",
"AUTH0_CLIENT_SECRET",
"GOOGLE_JSON_KEY",
"ALLOW_OVERRIDE_ANONYMOUS",
"GA_VIEW_ID",
"HOST",
].forEach((i)=>{
console.assert(`Env var process.env.${i} is required but not set.`)
});

myLogger.debug(`Setting Google Analytics with Tracking Id = `, process.env.OPEN_GOLINKS_GA_ID);
app.locals.siteName = process.env.OPEN_GOLINKS_SITE_NAME || `Open GoLinks`;
Expand All @@ -42,7 +52,7 @@ const strategy = new Auth0Strategy({
domain: process.env.AUTH0_DOMAIN,
clientID: process.env.AUTH0_CLIENT_ID,
clientSecret: process.env.AUTH0_CLIENT_SECRET, // Replace this with the client secret for your app
callbackURL: `http://${process.env.OPEN_GOLINKS_SITE_HOST}/callback` || `http://localhost:${PORT}/callback`,
callbackURL: `http://${process.env.OPEN_GOLINKS_SITE_HOST}/callback`, // TODO: callback HTTPS instead of HTTP
},
function (accessToken, refreshToken, extraParams, profile, done) {
// accessToken is the token to call Auth0 API (not needed in the most cases)
Expand Down Expand Up @@ -101,7 +111,7 @@ const main = async () => {
myLogger.debug(`Result:`, res.locals.loggedIn);
next();
});

app.use(ua.middleware(process.env.OPEN_GOLINKS_GA_ID, {cookieName: '_ga'}));
app.use((req: any, res: any, next: any) => {
if (req.user && req.user.emails) {
Expand Down
1 change: 1 addition & 0 deletions src/routes/apiv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ apiV2Router.get(`/gettoken`, asyncHandler(async (req, res) => {
})
)
apiV2Router.get(`/getviewId`, asyncHandler(async (req, res) => {
// https://ibb.co/xCJrNJ0
return res.send(process.env.GA_VIEW_ID)
})
)
Expand Down
1 change: 1 addition & 0 deletions src/routes/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const isEditable = function (existingLinkAuthor, reqeustingUser) {

export const getJWTClientAccessToekn = async function () {
const {JWT} = require('google-auth-library');
// An Base64 encoded version of Google Cloud Console service account json key private credentials
let decoded = Buffer.from(process.env.GOOGLE_JSON_KEY, 'base64').toString();
const keys = JSON.parse(decoded);
const client = new JWT(
Expand Down

0 comments on commit 1073af3

Please sign in to comment.