mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-26 06:47:17 +10:00
Equalize logger setup in server and browser
Set up logger in the server side with the same parameters as in the browser and clean the environment variables out of the server/log.js file. Code commenting improved.
This commit is contained in:
parent
81e945eae3
commit
1882e25d00
5 changed files with 24 additions and 13 deletions
|
|
@ -31,19 +31,24 @@ const fs = require('fs');
|
|||
const log = require('./log');
|
||||
|
||||
const buildPath = path.resolve(__dirname, '..', 'build');
|
||||
const dev = process.env.NODE_ENV !== 'production';
|
||||
const ENV = process.env.NODE_ENV;
|
||||
const PORT = process.env.PORT || 4000;
|
||||
const CLIENT_ID = process.env.REACT_APP_SHARETRIBE_SDK_CLIENT_ID ||
|
||||
'08ec69f6-d37e-414d-83eb-324e94afddf0';
|
||||
const BASE_URL = process.env.REACT_APP_SHARETRIBE_SDK_BASE_URL || 'http://localhost:8088';
|
||||
const ENFORCE_SSL = process.env.SERVER_SHARETRIBE_ENFORCE_SSL === 'true';
|
||||
const TRUST_PROXY = process.env.SERVER_SHARETRIBE_TRUST_PROXY || null;
|
||||
const SENTRY_DSN = process.env.SERVER_SENTRY_DSN;
|
||||
const dev = ENV !== 'production';
|
||||
const app = express();
|
||||
|
||||
const errorPage = fs.readFileSync(path.join(buildPath, '500.html'), 'utf-8');
|
||||
|
||||
// Error request handler
|
||||
log.setup();
|
||||
// Setup error logger
|
||||
log.setup(SENTRY_DSN, ENV);
|
||||
// Add logger request handler. In case Sentry is set up
|
||||
// request information is added to error context when sent
|
||||
// to Sentry.
|
||||
app.use(log.requestHandler());
|
||||
|
||||
// The helmet middleware sets various HTTP headers to improve security.
|
||||
|
|
@ -156,7 +161,8 @@ app.get('*', (req, res) => {
|
|||
});
|
||||
});
|
||||
|
||||
// Error handler that logs error responses
|
||||
// Set error handler. If Sentry is set up, all error responses
|
||||
// (500 and up) will be logged there.
|
||||
app.use(log.errorHandler());
|
||||
|
||||
app.listen(PORT, () => {
|
||||
|
|
|
|||
|
|
@ -5,21 +5,24 @@
|
|||
*/
|
||||
|
||||
const Raven = require('raven');
|
||||
const SENTRY_DSN = process.env.SERVER_SENTRY_DSN;
|
||||
const ENV = process.env.NODE_ENV;
|
||||
|
||||
// Sentry client key
|
||||
let SENTRY_DSN;
|
||||
|
||||
/**
|
||||
* Set up error loggin. If a Sentry DSN is defined
|
||||
* Sentry client is configured.
|
||||
*/
|
||||
exports.setup = () => {
|
||||
if (SENTRY_DSN) {
|
||||
Raven.config(SENTRY_DSN, {
|
||||
environment: ENV,
|
||||
exports.setup = (sentryDsn, env) => {
|
||||
if (sentryDsn) {
|
||||
Raven.config(sentryDsn, {
|
||||
environment: env,
|
||||
autoBreadcrumbs: {
|
||||
http: true,
|
||||
},
|
||||
}).install();
|
||||
|
||||
SENTRY_DSN = sentryDsn;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ const sdkBaseUrl = process.env.REACT_APP_SHARETRIBE_SDK_BASE_URL || 'http://loca
|
|||
|
||||
const currency = process.env.REACT_APP_SHARETRIBE_MARKETPLACE_CURRENCY || 'USD';
|
||||
|
||||
// Sentry DSN (Data Source Name), a client key for authenticating calls to Sentry
|
||||
const sentryDsn = process.env.REACT_APP_PUBLIC_SENTRY_DSN;
|
||||
|
||||
// Currency formatting options.
|
||||
|
|
|
|||
|
|
@ -74,7 +74,8 @@ if (typeof window !== 'undefined') {
|
|||
|
||||
setupStripe();
|
||||
render(store);
|
||||
log.setup(config.sentryDsn);
|
||||
// set up logger with Sentry DSN client key and environment
|
||||
log.setup(config.sentryDsn, config.env);
|
||||
|
||||
if (config.dev) {
|
||||
// Expose stuff for the browser REPL
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ import Raven from 'raven-js';
|
|||
*
|
||||
* @param {String} sentryDsn A public Sentry DSN
|
||||
*/
|
||||
export const setup = sentryDsn => {
|
||||
export const setup = (sentryDsn, env) => {
|
||||
if (sentryDsn !== undefined) {
|
||||
Raven.config(sentryDsn).install();
|
||||
Raven.config(sentryDsn, { environment: env }).install();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue