Provide Sentry token to Sentry API through env variable

This commit is contained in:
Wojciech Adaszynski
2020-05-18 11:30:02 +02:00
parent 3d4249b673
commit 807febae5a
3 changed files with 8 additions and 4 deletions
+6 -1
View File
@@ -22,7 +22,12 @@ export async function createRouter(
rootLogger: Logger,
): Promise<express.Router> {
const router = Router();
const sentryForwarder = new SentryApiForwarder('');
const SENTRY_TOKEN = process.env.SENTRY_TOKEN;
if (!SENTRY_TOKEN) {
console.error('Sentry token must be provided in env to start the API.');
process.exit(1);
}
const sentryForwarder = new SentryApiForwarder(SENTRY_TOKEN);
const logger = rootLogger.child({ plugin: 'sentry' });
router.get('*', (req, res) => sentryForwarder.fowardRequest(req, res));
@@ -18,8 +18,6 @@ import { Server } from 'http';
import { Logger } from 'winston';
import { createStandaloneApplication } from './standaloneApplication';
const PORT = 5009;
export async function startStandaloneServer(
parentLogger: Logger,
): Promise<Server> {
@@ -29,6 +27,7 @@ export async function startStandaloneServer(
const app = await createStandaloneApplication(logger);
logger.debug('Starting application server...');
const PORT = parseInt(process.env.PORT || '5001', 10);
return await new Promise((resolve, reject) => {
const server = app.listen(PORT, (err?: Error) => {
if (err) {
+1 -1
View File
@@ -18,7 +18,7 @@ import { MockSentryApi } from './mock-api';
import { ProductionSentryApi } from './production-api';
export function sentryApiFactory(organization: string): SentryApi {
if (process.env.NODE_ENV === 'production') {
if (process.env.NODE_ENV !== 'production') {
return new ProductionSentryApi(organization);
}
return new MockSentryApi();