Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
...req.headers,
body: req.body,
query: req.query,
timestamp: Date.now()
})
res.status(200).end()
})
// Resend payload via the event emitter
app.post('/:channel/redeliver', (req, res) => {
events.emit(req.params.channel, req.body)
res.status(200).end()
})
if (process.env.SENTRY_DSN) {
app.use(Raven.errorHandler())
}
return app
}
app.set('trust proxy', true);
app.set('config', config);
var usePort = config.get('app:port');
if (port) {
usePort = port;
}
app.set('port', usePort);
app.set('views', path.join(__dirname, '/views'));
// Sentry monitoring
var sentryDSN = config.get('sentryDSN');
if (sentryDSN != null) {
Raven.config(sentryDSN).install();
app.use(Raven.requestHandler());
app.use(Raven.errorHandler());
// Fallthrough error handler
app.use(function onError(err, req, res, next) {
// The error id is attached to `res.sentry` to be returned
// and optionally displayed to the user for support.
res.statusCode = 500;
res.end('An error occurred: ' + res.sentry + '\n');
});
} else {
console.log('Sentry DSN not configured');
}
// Middlewares
if (config.get('env') == 'test') {
app.use(express.static(path.join(__dirname, '/../tests/data')));
}
// Why the checking on params? Do we reach this code if params is falsy?
variables: params && params.variables,
query: (params && params.query)!,
}),
validationRules: QUERY_DEPTH_LIMIT
? [depthLimit(QUERY_DEPTH_LIMIT)]
: null,
extensions: enableRequestLogging
? fetchLoggerRequestDone(requestID)
: undefined,
}
})
)
if (enableSentry) {
app.use(raven.errorHandler())
}
return app
}
} else {
res.redirect('/')
}
} catch (err) {
next(err)
}
})
// Route to React client app
app.use(express.static(join(__dirname + '/../client/build')))
app.get('*', (req, res) => {
res.sendFile(join(__dirname + '/../client/build/index.html'))
})
// Sentry error reporting
app.use(raven.errorHandler())
app.use(function onError(err, req, res, next) {
console.log(err)
// The error id is attached to `res.sentry` to be returned
// and optionally displayed to the user for support.
res.statusCode = 500
res.end(res.sentry + '\n')
})
export default app
app.configure(require('feathers-logger')(logger));
// Load app configuration
app.configure(configuration(path.join(__dirname, '..')));
if (app.get('sentry').dns !== undefined && app.get('sentry').dns !== 'SENTRY_DNS') {
// LOGGING IS ENABLED
app.info('SENTRY LOGGING IS ENABLED');
// Must configure Raven before doing anything else with it
Raven.config(app.get('sentry').dns, app.get('sentry').options).install();
// The request handler must be the first middleware on the app
app.use(Raven.requestHandler());
// The error handler must be before any other error middleware
app.use(Raven.errorHandler());
// Optional fallthrough error handler
app.use(function onError(err, req, res) {
// The error id is attached to `res.sentry` to be returned
// and optionally displayed to the user for support.
res.statusCode = 500;
res.end(res.sentry + '\n');
});
}
// Enable CORS, security, compression, favicon and body parsing
app.use(cors());
app.use(helmet());
app.use(compress());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(favicon(path.join(app.get('public'), 'favicon.ico')));
app.configure(services);
// Set up event channels (see channels.js)
app.configure(channels);
app.use('/', homepage(app));
if (process.env.SENTRY_DSN) {
/*
* The Sentry error handler must be installed _after_ our other application
* handlers, but must be the _first_ error handler installed in Express
*
* See:
* https://docs.sentry.io/platforms/javascript/express/?platform=javascript
*/
app.use(Raven.errorHandler());
}
// Configure a middleware for 404s and the error handler
app.use(express.notFound());
app.use((err, req, res, next) => {
if (res.headersSent) {
return next(err);
}
if (!err.statusCode) {
err.statusCode = (err.code ? err.code : 500);
}
if (!err.message) {
err.message = 'Unexpected server error';
}
/* Avoid cluttering the test logs with expected errors and exceptions */
constructor() {
this.app = express();
if (useRaven()) {
this.app.use(Raven.requestHandler());
this.app.use(Raven.errorHandler());
}
this.app.use(bodyParser.json({ limit: "250mb" }));
this.app.use(expressWinston.logger({
winstonInstance: winston,
dynamicMeta: this.requestLog,
requestFilter(req, propName) {
if (propName !== "headers") {
return req[propName];
}
},
}));
this.app.use(express.static("public"));
this.route("/", (req, res) => __awaiter(this, void 0, void 0, function* () {
const request = Hub.ActionRequest.fromRequest(req);
const actions = yield Hub.allActions({ lookerVersion: request.lookerVersion });
const response = {
'response-time': tokens['response-time'](req, res)
},
'request'
);
})
);
app.use(render);
app.use((req, res) => {
res.status(404).send({
message: 'Not Found'
});
});
app.use(Raven.errorHandler());
app.use((err, req, res, next) => {
log.error(err, 'internal_error');
res.statusCode = 500;
res.end('Internal Error');
});
export default app;