diff --git a/src/controllers/base.controller.js b/src/controllers/base.controller.js index a44d948..0ca951a 100644 --- a/src/controllers/base.controller.js +++ b/src/controllers/base.controller.js @@ -20,6 +20,37 @@ const jsonRpc = async (req, res) => { jsonRpcResponder(req, res, rpcRes) } +const auth = async (req, res) => { + const xAuthTokenHeader = req.headers?.['x-auth-token'] + const xOriginalURIHeader = req.headers?.['x-original-uri'] + const params = xOriginalURIHeader.split('?')[1] + + const queryToken = req.query?.token ?? null + const uriToken = new URLSearchParams(params).get('token') + const headerToken = (uriToken && typeof uriToken === 'string') + ? uriToken + : xAuthTokenHeader + const token = (queryToken && typeof queryToken === 'string') + ? queryToken + : headerToken + + if (!token) { + res.status(401).send() + + return + } + + const query = { + action: 'verifyUser', + args: [{ auth: { token } }] + } + + const rpcRes = await grenacheClientService.request(query) + + jsonRpcResponder(req, res, rpcRes) +} + module.exports = { - jsonRpc + jsonRpc, + auth } diff --git a/src/routes/index.js b/src/routes/index.js index e852ca8..56953e2 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -10,6 +10,7 @@ const controllers = require('../controllers') const baseController = asyncErrorCatcher(controllers.baseController) router.post('/json-rpc', baseController.jsonRpc) +router.get('/auth', baseController.auth) /** * @deprecated diff --git a/src/services/log.service.js b/src/services/log.service.js index f21869a..095b498 100644 --- a/src/services/log.service.js +++ b/src/services/log.service.js @@ -12,9 +12,9 @@ const basePath = 'logs/' const ext = '.log' const logLabel = isDevEnv ? ':app-dev' : ':app' -const pathError = isEnable && (isProdEnv || isDevEnv) ? `${basePath}error${ext}` : null -const pathExcLogger = isEnable && (isProdEnv || isDevEnv) ? `${basePath}exceptions-logger${ext}` : null -const pathLog = isEnable && isDevEnv ? `${basePath}log${ext}` : null +const pathError = isEnable && (isProdEnv || isDevEnv) ? `${basePath}errors-express${ext}` : null +const pathExcLogger = isEnable && (isProdEnv || isDevEnv) ? `${basePath}exceptions-express${ext}` : null +const pathLog = isEnable && isDevEnv ? `${basePath}logs-express${ext}` : null const enableConsole = isEnable && isDevEnv const enableColor = isEnable && isDevEnv const enableColorPathError = false