refactor: eject platform env, extract oauth

This commit is contained in:
EnixCoda 2019-11-04 20:19:47 +08:00
parent 53796dec97
commit 83690816cf
No known key found for this signature in database
GPG key ID: 0C1A07377913A1DD
3 changed files with 8 additions and 9 deletions

View file

@ -1,6 +1,6 @@
import * as Sentry from '@sentry/browser'
import { Middleware } from 'driver/connect.js'
import { IN_PRODUCTION_MODE, PLATFORM } from 'env'
import { IN_PRODUCTION_MODE } from 'env'
import { version } from '../package.json'
const PUBLIC_KEY = 'd22ec5c9cc874539a51c78388c12e3b0'
@ -10,11 +10,9 @@ const sentryOptions: Sentry.BrowserOptions = {
dsn: `https://${PUBLIC_KEY}@sentry.io/${PROJECT_ID}`,
release: `v${version}`,
environment: IN_PRODUCTION_MODE ? 'production' : 'development',
}
if (PLATFORM !== 'chrome') {
// Not safe to activate all integrations in non-Chrome environments where Gitako may not run in top context
// https://docs.sentry.io/platforms/javascript/#sdk-integrations
sentryOptions.integrations = ints => ints.filter(({ name }) => name !== 'TryCatch')
integrations: ints => ints.filter(({ name }) => name !== 'TryCatch'),
}
Sentry.init(sentryOptions)

View file

@ -1,4 +1,5 @@
import Icon from 'components/Icon'
import { oauth } from 'env'
import * as React from 'react'
import configHelper, { Config, configKeys } from 'utils/configHelper'
import { friendlyFormatShortcut, JSONRequest, parseURLSearch } from 'utils/general'
@ -14,11 +15,6 @@ const wikiLinks = {
createAccessToken: `${WIKI_HOME_LINK}/How-to-create-access-token-for-Gitako%3F`,
}
const oauth = {
clientId: process.env.GITHUB_OAUTH_CLIENT_ID,
clientSecret: process.env.GITHUB_OAUTH_CLIENT_SECRET,
}
const ACCESS_TOKEN_REGEXP = /^[0-9a-f]{40}$/
type Props = {

View file

@ -4,3 +4,8 @@ type KnownPlatform = 'chrome' | 'firefox'
type Platform = KnownPlatform | Exclude<string, keyof KnownPlatform>
export const PLATFORM: Platform = process.env.PLATFORM || 'unknown'
export const oauth = {
clientId: process.env.GITHUB_OAUTH_CLIENT_ID,
clientSecret: process.env.GITHUB_OAUTH_CLIENT_SECRET,
}