Fix minor exception in getting claimId util, fix metrics

This commit is contained in:
Shawn 2018-10-09 13:10:06 -05:00
parent 4aaff575b3
commit bacb05abe8
5 changed files with 38 additions and 7 deletions

View file

@ -12,7 +12,7 @@ const getClaimIdByChannel = async (channelName, channelClaimId, claimName) => {
channelId = await db.Certificate.getLongChannelId(channelName, channelClaimId);
}
let claimId = await chainquery.claim.queries.getClaimIdByLongChannelId(longChannelId, claimName);
let claimId = await chainquery.claim.queries.getClaimIdByLongChannelId(channelId, claimName);
if(claimId === null) {
claimId = db.Claim.getClaimIdByLongChannelId(longChannelId, claimName);

View file

@ -30,9 +30,12 @@ const {
function logMetricsMiddleware(req, res, next) {
res.on('finish', () => {
const userAgent = req.get('user-agent');
const routePath = httpContext.get('routePath');
db.Metrics.create({
isInternal: /node\-fetch/.test(userAgent),
isChannel: res.isChannel,
claimId: res.claimId,
routePath: httpContext.get('routePath'),
params: JSON.stringify(req.params),
ip: req.headers['x-forwarded-for'] || req.connection.remoteAddress,
@ -97,7 +100,7 @@ function Server () {
app.use(speechPassport.session());
// configure handlebars & register it with express app
const viewsPath = Path.resolve(process.cwd(), 'server/views');
const viewsPath = Path.resolve(process.cwd(), 'node_modules/spee.ch/server/views');
app.engine('handlebars', expressHandlebars({
async : false,
dataType : 'text',

View file

@ -1,6 +1,6 @@
module.exports = (sequelize, { BOOLEAN, DATE, STRING }) => {
const RequestMetrics = sequelize.define(
'RequestMetrics',
const Metrics = sequelize.define(
'Metrics',
{
time: {
type: DATE(6),
@ -9,6 +9,10 @@ module.exports = (sequelize, { BOOLEAN, DATE, STRING }) => {
isInternal: {
type: BOOLEAN,
},
isChannel: {
type: BOOLEAN,
defaultValue: false,
},
claimId: {
type: STRING,
defaultValue: null,
@ -43,11 +47,11 @@ module.exports = (sequelize, { BOOLEAN, DATE, STRING }) => {
timestamps: false, // don't use default timestamps columns
indexes: [
{
fields: ['isInternal', 'time', 'routePath'],
fields: ['isInternal', 'isChannel', 'time', 'claimId', 'routePath'],
},
],
}
);
return RequestMetrics;
return Metrics;
};

View file

@ -67,7 +67,19 @@ module.exports = function (req, res) {
var runSaga = action !== false && saga !== false;
var renderPage = function renderPage(store) {
// render component to a string
// Workaround, remove when a solution for async httpContext exists
var showState = store.getState().show;
var assetKeys = Object.keys(showState.assetList);
if (assetKeys.length !== 0) {
res.claimId = showState.assetList[assetKeys[0]].claimId;
} else {
var channelKeys = Object.keys(showState.channelList);
res.claimId = showState.channelList[channelKeys[0]].longId;
res.isChannel = true;
} // render component to a string
var html = (0, _server.renderToString)(_react.default.createElement(_reactRedux.Provider, {
store: store
}, _react.default.createElement(_reactRouterDom.StaticRouter, {

View file

@ -32,6 +32,18 @@ module.exports = (req, res) => {
const runSaga = (action !== false && saga !== false);
const renderPage = (store) => {
// Workaround, remove when a solution for async httpContext exists
const showState = store.getState().show;
const assetKeys = Object.keys(showState.assetList);
if(assetKeys.length !== 0) {
res.claimId = showState.assetList[assetKeys[0]].claimId;
} else {
const channelKeys = Object.keys(showState.channelList);
res.claimId = showState.channelList[channelKeys[0]].longId;
res.isChannel = true;
}
// render component to a string
const html = renderToString(
<Provider store={store}>