better config for store. better error logging for
redis connection
This commit is contained in:
parent
5dd83863cb
commit
ca8d50241e
6
.env
6
.env
@ -1,7 +1,7 @@
|
|||||||
PORT = 3000
|
PORT = 3000
|
||||||
|
|
||||||
## Store type 'local-storage' or 'redis' supported
|
## Store type 'local-storage' or 'redis' supported
|
||||||
STORE = local-storage
|
STORE_PROVIDER = redis
|
||||||
|
|
||||||
# use if STORE = redis
|
# for example if STORE = redis
|
||||||
REDIS_URL = redis://localhost:6379
|
STORE_URL = redis://localhost:6379
|
||||||
@ -1,10 +1,12 @@
|
|||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
|
import config from "../../config/index.js";
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get("/", (req, res) => {
|
router.get("/", (req, res) => {
|
||||||
const config = {
|
res.send({
|
||||||
|
config: config,
|
||||||
env: process.env,
|
env: process.env,
|
||||||
};
|
});
|
||||||
res.send(config);
|
|
||||||
});
|
});
|
||||||
export default router;
|
export default router;
|
||||||
|
|||||||
@ -25,14 +25,15 @@ export default {
|
|||||||
level: process.env.LOG_LEVEL || "silly",
|
level: process.env.LOG_LEVEL || "silly",
|
||||||
},
|
},
|
||||||
|
|
||||||
redis: {
|
store: {
|
||||||
url: process.env.REDIS_URL || "redis://localhost:6379",
|
provider: process.env.STORE_PROVIDER || "local-storage",
|
||||||
|
url: process.env.STORE_URL || "redis://localhost:6379",
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API configs
|
* API configs
|
||||||
*/
|
*/
|
||||||
api: {
|
api: {
|
||||||
prefix: "/api",
|
prefix: process.env.API_PREFIX || "/api",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import Promise from "promise";
|
|||||||
const store = await createStore();
|
const store = await createStore();
|
||||||
|
|
||||||
async function createStore() {
|
async function createStore() {
|
||||||
if (process.env.STORE === "redis") {
|
if (config.store.provider === "redis") {
|
||||||
return {
|
return {
|
||||||
client: await createRedisClient(),
|
client: await createRedisClient(),
|
||||||
|
|
||||||
@ -37,10 +37,18 @@ async function createStore() {
|
|||||||
|
|
||||||
async function createRedisClient() {
|
async function createRedisClient() {
|
||||||
const client = createClient({
|
const client = createClient({
|
||||||
url: config.redis.url,
|
url: config.store.url,
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on("error", (err) => logger.error("Redis Client Error", err));
|
client.on("error", (err) => {
|
||||||
|
if (err.errors) {
|
||||||
|
err.errors.forEach((error) => {
|
||||||
|
logger.error(`Redis Client Error ${error}`);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
logger.error(`Redis Client Error ${err.message}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
await client.connect();
|
await client.connect();
|
||||||
logger.info(`Connect store to ${config.redis.url}`);
|
logger.info(`Connect store to ${config.redis.url}`);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user