reddish cache integration
This commit is contained in:
parent
e675be14b5
commit
045636da98
12
.env
12
.env
@ -7,18 +7,20 @@ NODE_ENV = development
|
||||
|
||||
TESTNET_DB_PORT = 5432
|
||||
TESTNET_DB_HOST = localhost
|
||||
TESTNET_DB_USERNAME = root
|
||||
TESTNET_DB_USERNAME = postgres
|
||||
TESTNET_DB_PASSWORD = blaze.ws
|
||||
TESTNET_DB_DATABASE = epic_data_new
|
||||
TESTNET_DB_DATABASE = epicnew
|
||||
|
||||
|
||||
FLOONET_DB_PORT = 5432
|
||||
FLOONET_DB_HOST = localhost
|
||||
FLOONET_DB_USERNAME = root
|
||||
FLOONET_DB_USERNAME = postgres
|
||||
FLOONET_DB_PASSWORD = blaze.ws
|
||||
FLOONET_DB_DATABASE = epic
|
||||
|
||||
FLOONET_DB_DATABASE = epicnew
|
||||
TESTNET_PEER_URL = http://116.203.152.58:3413/v1/peers/connected
|
||||
FLOONET_PEER_URL = http://116.203.152.58:13413/v1/peers/connected
|
||||
|
||||
TIME_ZONE = utc
|
||||
|
||||
REDIS_KEY = explorer2
|
||||
REDIS_EXPIRY = 60
|
@ -30,6 +30,7 @@
|
||||
"@nguniversal/express-engine": "^7.0.2",
|
||||
"@nguniversal/module-map-ngfactory-loader": "^7.0.2",
|
||||
"@ngx-translate/core": "^11.0.1",
|
||||
"axios": "^0.19.0",
|
||||
"babel-preset-es2015": "^6.24.1",
|
||||
"body-parser": "^1.19.0",
|
||||
"class-transformer": "^0.2.3",
|
||||
@ -46,6 +47,7 @@
|
||||
"pg": "^7.11.0",
|
||||
"pg-native": "^3.0.0",
|
||||
"plotly.js": "^1.48.3",
|
||||
"redis": "^2.8.0",
|
||||
"rxjs": "~6.4.0",
|
||||
"socket.io": "^2.2.0",
|
||||
"socket.io-client": "^2.2.0",
|
||||
@ -61,9 +63,11 @@
|
||||
"@angular/cli": "~8.0.2",
|
||||
"@angular/compiler-cli": "~8.0.0",
|
||||
"@angular/language-service": "~8.0.0",
|
||||
"@types/node": "~8.9.4",
|
||||
"@types/jasmine": "~3.3.8",
|
||||
"@types/jasminewd2": "~2.0.3",
|
||||
"@types/memory-cache": "^0.2.0",
|
||||
"@types/node": "~8.9.4",
|
||||
"@types/redis": "^2.8.13",
|
||||
"codelyzer": "^5.0.0",
|
||||
"jasmine-core": "~3.4.0",
|
||||
"jasmine-spec-reporter": "~4.2.1",
|
||||
|
@ -2,7 +2,7 @@ import express from 'express';
|
||||
import { Global } from "../global";
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { getRepository, getConnection } from 'typeorm';
|
||||
import { validationMiddleware } from '../middlewares';
|
||||
import { validationMiddleware, redisMiddleware } from '../middlewares';
|
||||
import {
|
||||
InternalServerErrorException,
|
||||
NoDataFoundException,
|
||||
@ -208,6 +208,7 @@ export class BlockchainBlockController {
|
||||
this.router.post(
|
||||
`${this.path}`,
|
||||
validationMiddleware(BlockchainBlockCreateDto),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockchainBlockCreate,
|
||||
);
|
||||
|
||||
@ -251,6 +252,7 @@ export class BlockchainBlockController {
|
||||
this.router.get(
|
||||
`${this.path}/totaldiff`,
|
||||
validationMiddleware(TotalDifficultyNBlockDto, true),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.TotalDifficultyNBlock,
|
||||
);
|
||||
|
||||
@ -286,6 +288,7 @@ export class BlockchainBlockController {
|
||||
this.router.get(
|
||||
`${this.path}/blockcount`,
|
||||
validationMiddleware(TotalDifficultyNBlockDto, true),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockCount,
|
||||
);
|
||||
|
||||
@ -315,6 +318,7 @@ export class BlockchainBlockController {
|
||||
this.router.get(
|
||||
`${this.path}/blockinterval`,
|
||||
validationMiddleware(TotalDifficultyNBlockDto, true),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockInterval,
|
||||
);
|
||||
|
||||
@ -350,6 +354,7 @@ export class BlockchainBlockController {
|
||||
this.router.get(
|
||||
`${this.path}/stackblock`,
|
||||
validationMiddleware(TotalDifficultyNBlockDto, true),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.StackBlock,
|
||||
);
|
||||
|
||||
@ -385,6 +390,7 @@ export class BlockchainBlockController {
|
||||
this.router.get(
|
||||
`${this.path}/blockpiechart`,
|
||||
validationMiddleware(TotalDifficultyNBlockDto, true),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockPieChart,
|
||||
);
|
||||
|
||||
@ -420,6 +426,7 @@ export class BlockchainBlockController {
|
||||
this.router.get(
|
||||
`${this.path}/hashrate`,
|
||||
validationMiddleware(TotalDifficultyNBlockDto, true),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.HashRate,
|
||||
);
|
||||
|
||||
@ -442,6 +449,7 @@ export class BlockchainBlockController {
|
||||
this.router.get(
|
||||
`${this.path}/latesblockdetails`,
|
||||
validationMiddleware(TotalDifficultyNBlockDto, true),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.LatestDifficultyNBlock,
|
||||
);
|
||||
|
||||
@ -477,6 +485,7 @@ export class BlockchainBlockController {
|
||||
this.router.get(
|
||||
`${this.path}/blockspersec`,
|
||||
validationMiddleware(TotalDifficultyNBlockDto, true),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockchainBlockPerSecond,
|
||||
);
|
||||
|
||||
@ -512,6 +521,7 @@ export class BlockchainBlockController {
|
||||
this.router.get(
|
||||
`${this.path}/supplygrowth`,
|
||||
validationMiddleware(TotalDifficultyNBlockDto, true),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.SupplyGrowth,
|
||||
);
|
||||
|
||||
@ -547,6 +557,7 @@ export class BlockchainBlockController {
|
||||
this.router.get(
|
||||
`${this.path}/blockminedchart`,
|
||||
validationMiddleware(TotalDifficultyNBlockDto, true),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockMineChart,
|
||||
);
|
||||
|
||||
@ -580,6 +591,7 @@ export class BlockchainBlockController {
|
||||
this.router.get(
|
||||
`${this.path}/list`,
|
||||
validationMiddleware(BlockchainBlockPaginationDto),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockchainBlockPagination,
|
||||
);
|
||||
|
||||
@ -608,6 +620,7 @@ export class BlockchainBlockController {
|
||||
this.router.get(
|
||||
`${this.path}/:hash`,
|
||||
validationMiddleware(BlockchainBlockSingleViewDto, true),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockchainBlockFetch,
|
||||
);
|
||||
|
||||
@ -637,6 +650,7 @@ export class BlockchainBlockController {
|
||||
this.router.patch(
|
||||
`${this.path}`,
|
||||
validationMiddleware(BlockchainBlockUpdateDto),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockchainBlockUpdate,
|
||||
);
|
||||
|
||||
@ -665,6 +679,7 @@ export class BlockchainBlockController {
|
||||
this.router.delete(
|
||||
`${this.path}/:hash`,
|
||||
validationMiddleware(BlockchainBlockSingleViewDto),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockchainBlockDelete,
|
||||
);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import express from 'express';
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { getRepository,getConnection } from 'typeorm';
|
||||
import { validationMiddleware } from '../middlewares';
|
||||
import { validationMiddleware, redisMiddleware } from '../middlewares';
|
||||
import {
|
||||
InternalServerErrorException,
|
||||
NoDataFoundException,
|
||||
@ -63,6 +63,7 @@ export class BlockchainInputController {
|
||||
this.router.post(
|
||||
`${this.path}`,
|
||||
validationMiddleware(BlockchainInputCreateDto),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockchainInputCreate,
|
||||
);
|
||||
|
||||
@ -101,6 +102,7 @@ export class BlockchainInputController {
|
||||
this.router.get(
|
||||
`${this.path}/list`,
|
||||
validationMiddleware(BlockchainInputPaginationDto),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockchainInputPagination,
|
||||
);
|
||||
|
||||
@ -129,6 +131,7 @@ export class BlockchainInputController {
|
||||
this.router.get(
|
||||
`${this.path}/:id`,
|
||||
validationMiddleware(BlockchainInputSingleViewDto),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockchainInputFetch,
|
||||
);
|
||||
|
||||
@ -158,6 +161,7 @@ export class BlockchainInputController {
|
||||
this.router.patch(
|
||||
`${this.path}`,
|
||||
validationMiddleware(BlockchainInputUpdateDto),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockchainInputUpdate,
|
||||
);
|
||||
|
||||
@ -186,6 +190,7 @@ export class BlockchainInputController {
|
||||
this.router.delete(
|
||||
`${this.path}/:id`,
|
||||
validationMiddleware(BlockchainInputSingleViewDto),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockchainInputDelete,
|
||||
);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import express from 'express';
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { getRepository, getConnection } from 'typeorm';
|
||||
import { validationMiddleware } from '../middlewares';
|
||||
import { validationMiddleware, redisMiddleware } from '../middlewares';
|
||||
import { Global } from "../global";
|
||||
import * as path from 'path';
|
||||
import {
|
||||
@ -84,6 +84,7 @@ export class BlockchainKernelController {
|
||||
this.router.post(
|
||||
`${this.path}`,
|
||||
validationMiddleware(BlockchainKernelCreateDto),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockchainKernelCreate,
|
||||
);
|
||||
|
||||
@ -119,6 +120,7 @@ export class BlockchainKernelController {
|
||||
this.router.get(
|
||||
`${this.path}/transactionfee`,
|
||||
validationMiddleware(TransactionFeeDto, true),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.TransactionFee,
|
||||
);
|
||||
|
||||
@ -211,6 +213,7 @@ export class BlockchainKernelController {
|
||||
this.router.get(
|
||||
`${this.path}/transactionheatmap`,
|
||||
validationMiddleware(TransactionFeeDto, true),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.HeatmapChart,
|
||||
);
|
||||
|
||||
@ -246,6 +249,7 @@ export class BlockchainKernelController {
|
||||
this.router.get(
|
||||
`${this.path}/transactionlinechart`,
|
||||
validationMiddleware(TransactionFeeDto, true),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.TransactionChart,
|
||||
);
|
||||
|
||||
@ -284,6 +288,7 @@ export class BlockchainKernelController {
|
||||
this.router.get(
|
||||
`${this.path}/list`,
|
||||
validationMiddleware(BlockchainKernelPaginationDto),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockchainKernelPagination,
|
||||
);
|
||||
|
||||
@ -312,6 +317,7 @@ export class BlockchainKernelController {
|
||||
this.router.get(
|
||||
`${this.path}/:id`,
|
||||
validationMiddleware(BlockchainKernelSingleViewDto),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockchainKernelFetch,
|
||||
);
|
||||
|
||||
@ -341,6 +347,7 @@ export class BlockchainKernelController {
|
||||
this.router.patch(
|
||||
`${this.path}`,
|
||||
validationMiddleware(BlockchainKernelUpdateDto),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockchainKernelUpdate,
|
||||
);
|
||||
|
||||
@ -369,6 +376,7 @@ export class BlockchainKernelController {
|
||||
this.router.delete(
|
||||
`${this.path}/:id`,
|
||||
validationMiddleware(BlockchainKernelSingleViewDto),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockchainKernelDelete,
|
||||
);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import express from 'express';
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { getRepository, getConnection } from 'typeorm';
|
||||
import { validationMiddleware } from '../middlewares';
|
||||
import { validationMiddleware, redisMiddleware } from '../middlewares';
|
||||
import { Global } from "../global";
|
||||
|
||||
import {
|
||||
@ -77,6 +77,7 @@ export class BlockchainOutputController {
|
||||
this.router.post(
|
||||
`${this.path}`,
|
||||
validationMiddleware(BlockchainOutputCreateDto),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockchainOutputCreate,
|
||||
);
|
||||
|
||||
@ -115,6 +116,7 @@ export class BlockchainOutputController {
|
||||
this.router.get(
|
||||
`${this.path}/list`,
|
||||
validationMiddleware(BlockchainOutputPaginationDto),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockchainOutputPagination,
|
||||
);
|
||||
|
||||
@ -143,6 +145,7 @@ export class BlockchainOutputController {
|
||||
this.router.get(
|
||||
`${this.path}/:id`,
|
||||
validationMiddleware(BlockchainOutputSingleViewDto),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockchainOutputFetch,
|
||||
);
|
||||
|
||||
@ -172,6 +175,7 @@ export class BlockchainOutputController {
|
||||
this.router.patch(
|
||||
`${this.path}`,
|
||||
validationMiddleware(BlockchainOutputUpdateDto),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockchainOutputUpdate,
|
||||
);
|
||||
|
||||
@ -200,6 +204,7 @@ export class BlockchainOutputController {
|
||||
this.router.delete(
|
||||
`${this.path}/:id`,
|
||||
validationMiddleware(BlockchainOutputSingleViewDto),
|
||||
redisMiddleware(process.env.REDIS_EXPIRY),
|
||||
this.BlockchainOutputDelete,
|
||||
);
|
||||
}
|
||||
|
@ -1,2 +1,3 @@
|
||||
export * from './error.middleware';
|
||||
export * from './validator.middleware';
|
||||
export * from './redis.middleware';
|
45
server/middlewares/redis.middleware.ts
Normal file
45
server/middlewares/redis.middleware.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import { NextFunction, Request, Response } from 'express';
|
||||
import { HttpException } from '../exceptions/index';
|
||||
import * as redis from 'redis';
|
||||
import { Global } from "../global";
|
||||
import { Duration } from 'moment';
|
||||
|
||||
// connect to Redis
|
||||
const REDIS_URL = process.env.REDIS_URL;
|
||||
const client = redis.createClient(REDIS_URL);
|
||||
|
||||
client.on('connect', () => {
|
||||
console.log(`connected to redis`);
|
||||
});
|
||||
client.on('error', err => {
|
||||
console.log(`Error: ${err}`);
|
||||
});
|
||||
|
||||
export function redisMiddleware(
|
||||
duration: any,
|
||||
) {
|
||||
console.log(duration);
|
||||
return (request, response, next) => {
|
||||
// Global.network = request.headers.network;
|
||||
let key = process.env.REDIS_KEY + Global.network + request.originalUrl || request.url
|
||||
client.get(key, function(err, reply){
|
||||
if(reply && duration!=0){
|
||||
console.log("key : ", key);
|
||||
console.log("reply : ", reply);
|
||||
console.log("---------------------------------------------------------------------------------------");
|
||||
console.log(`enabled`);
|
||||
response.send(reply);
|
||||
}else{
|
||||
console.log(`raw`);
|
||||
response.sendResponse = response.send;
|
||||
response.send = (body) => {
|
||||
client.set(key, JSON.stringify(body), 'EX', duration, function(err){
|
||||
//client.set(key, JSON.stringify(body));
|
||||
response.sendResponse(body);
|
||||
});
|
||||
}
|
||||
next();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
|
||||
export const environment = {
|
||||
production: false,
|
||||
domain: '/',
|
||||
domain: 'https://explorer.epic.tech/',
|
||||
apiUrl: 'https://explorer.epic.tech/epic_explorer/v1',
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user