Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update master with last changes #24

Merged
merged 4 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/controllers/base.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/services/log.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down