Fix minor exception in getting claimId util, fix metrics
This commit is contained in:
parent
4aaff575b3
commit
bacb05abe8
5 changed files with 38 additions and 7 deletions
|
@ -12,7 +12,7 @@ const getClaimIdByChannel = async (channelName, channelClaimId, claimName) => {
|
||||||
channelId = await db.Certificate.getLongChannelId(channelName, channelClaimId);
|
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) {
|
if(claimId === null) {
|
||||||
claimId = db.Claim.getClaimIdByLongChannelId(longChannelId, claimName);
|
claimId = db.Claim.getClaimIdByLongChannelId(longChannelId, claimName);
|
||||||
|
|
|
@ -30,9 +30,12 @@ const {
|
||||||
function logMetricsMiddleware(req, res, next) {
|
function logMetricsMiddleware(req, res, next) {
|
||||||
res.on('finish', () => {
|
res.on('finish', () => {
|
||||||
const userAgent = req.get('user-agent');
|
const userAgent = req.get('user-agent');
|
||||||
|
const routePath = httpContext.get('routePath');
|
||||||
|
|
||||||
db.Metrics.create({
|
db.Metrics.create({
|
||||||
isInternal: /node\-fetch/.test(userAgent),
|
isInternal: /node\-fetch/.test(userAgent),
|
||||||
|
isChannel: res.isChannel,
|
||||||
|
claimId: res.claimId,
|
||||||
routePath: httpContext.get('routePath'),
|
routePath: httpContext.get('routePath'),
|
||||||
params: JSON.stringify(req.params),
|
params: JSON.stringify(req.params),
|
||||||
ip: req.headers['x-forwarded-for'] || req.connection.remoteAddress,
|
ip: req.headers['x-forwarded-for'] || req.connection.remoteAddress,
|
||||||
|
@ -97,7 +100,7 @@ function Server () {
|
||||||
app.use(speechPassport.session());
|
app.use(speechPassport.session());
|
||||||
|
|
||||||
// configure handlebars & register it with express app
|
// 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({
|
app.engine('handlebars', expressHandlebars({
|
||||||
async : false,
|
async : false,
|
||||||
dataType : 'text',
|
dataType : 'text',
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module.exports = (sequelize, { BOOLEAN, DATE, STRING }) => {
|
module.exports = (sequelize, { BOOLEAN, DATE, STRING }) => {
|
||||||
const RequestMetrics = sequelize.define(
|
const Metrics = sequelize.define(
|
||||||
'RequestMetrics',
|
'Metrics',
|
||||||
{
|
{
|
||||||
time: {
|
time: {
|
||||||
type: DATE(6),
|
type: DATE(6),
|
||||||
|
@ -9,6 +9,10 @@ module.exports = (sequelize, { BOOLEAN, DATE, STRING }) => {
|
||||||
isInternal: {
|
isInternal: {
|
||||||
type: BOOLEAN,
|
type: BOOLEAN,
|
||||||
},
|
},
|
||||||
|
isChannel: {
|
||||||
|
type: BOOLEAN,
|
||||||
|
defaultValue: false,
|
||||||
|
},
|
||||||
claimId: {
|
claimId: {
|
||||||
type: STRING,
|
type: STRING,
|
||||||
defaultValue: null,
|
defaultValue: null,
|
||||||
|
@ -43,11 +47,11 @@ module.exports = (sequelize, { BOOLEAN, DATE, STRING }) => {
|
||||||
timestamps: false, // don't use default timestamps columns
|
timestamps: false, // don't use default timestamps columns
|
||||||
indexes: [
|
indexes: [
|
||||||
{
|
{
|
||||||
fields: ['isInternal', 'time', 'routePath'],
|
fields: ['isInternal', 'isChannel', 'time', 'claimId', 'routePath'],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return RequestMetrics;
|
return Metrics;
|
||||||
};
|
};
|
||||||
|
|
|
@ -67,7 +67,19 @@ module.exports = function (req, res) {
|
||||||
var runSaga = action !== false && saga !== false;
|
var runSaga = action !== false && saga !== false;
|
||||||
|
|
||||||
var renderPage = function renderPage(store) {
|
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, {
|
var html = (0, _server.renderToString)(_react.default.createElement(_reactRedux.Provider, {
|
||||||
store: store
|
store: store
|
||||||
}, _react.default.createElement(_reactRouterDom.StaticRouter, {
|
}, _react.default.createElement(_reactRouterDom.StaticRouter, {
|
||||||
|
|
|
@ -32,6 +32,18 @@ module.exports = (req, res) => {
|
||||||
const runSaga = (action !== false && saga !== false);
|
const runSaga = (action !== false && saga !== false);
|
||||||
|
|
||||||
const renderPage = (store) => {
|
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
|
// render component to a string
|
||||||
const html = renderToString(
|
const html = renderToString(
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
|
|
Loading…
Reference in a new issue