diff --git a/client/utils/consts.js b/client/utils/consts.js index bf1bf9e6..fed26ba5 100644 --- a/client/utils/consts.js +++ b/client/utils/consts.js @@ -1,11 +1,7 @@ -import consts from './consts.json' - /** * Nuxt (client) defaults constants. * - * Should mirror with ../server/utils/consts.js - * But here, we should have only what matters for the client. */ -export default Object.freeze( - ...consts -) +export default Object.freeze({ + SHOW_EXAMPLES: true +}) diff --git a/client/utils/consts.json b/client/utils/consts.json deleted file mode 100644 index a863de0f..00000000 --- a/client/utils/consts.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "APP": "hare", - "API": "hpi", - "BASE_API": "/hpi", - "SESS_KEY": "hare:sess", - "COOKIE_JWT": "hare_jwt", - "SHOW_EXAMPLES": true, - "AXIOS_DEFAULT_TIMEOUT": 50000 -} diff --git a/server/api/routes-auth.js b/server/api/routes-auth.js index 95f5fcfa..4a5fecb7 100644 --- a/server/api/routes-auth.js +++ b/server/api/routes-auth.js @@ -76,6 +76,7 @@ router.post('/auth/login', async (ctx) => { ctx.throw(401, translator.translate('auth.login.captcha.invalid')) } try { + console.log(11111) // Assuming your API only wants base64 encoded version of the password const password = Buffer.from(user.password).toString('base64') const payload = { diff --git a/server/api/routes-menu.js b/server/api/routes-menu.js index 9decea21..58290da2 100644 --- a/server/api/routes-menu.js +++ b/server/api/routes-menu.js @@ -1,8 +1,8 @@ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /* Route to handle /menu */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -import koaRouter from 'koa-router' -import consts from '../utils/consts' +const koaRouter = require('koa-router') +const consts = require('../utils/consts') const SHOW_EXAMPLES = consts.SHOW_EXAMPLES === true diff --git a/server/utils/consts.js b/server/utils/consts.js index eaa74fbe..d8bec098 100644 --- a/server/utils/consts.js +++ b/server/utils/consts.js @@ -1,17 +1,10 @@ -/** - * Nuxt Server API Side-Car (Using Koa). - * - * Should mirror with ../client/utils/consts.js - * But here, we should have only what matters for the backend. - * - * In other words, where Nuxt will read data from. - * This will be what serves all data to Nuxt client, - * and will read from our backends. - * It will also ensure only authenticated requests yields data. - */ - -import consts from '../../client/utils/consts.json' - +const APP = 'hare' +const API = 'hpi' +const BASE_API = '/hpi' +const SESS_KEY = 'hare:sess' +const COOKIE_JWT = 'hare_jwt' +const SHOW_EXAMPLES = true +const AXIOS_DEFAULT_TIMEOUT = 50000 const HOST = process.env.HOST || '0.0.0.0' const PORT = process.env.PORT || '3000' const LB_ADDR = process.env.LB_ADDR || `http://${HOST}:${PORT}/hpi` @@ -28,12 +21,21 @@ const LB_ADDR = process.env.LB_ADDR || `http://${HOST}:${PORT}/hpi` */ const ENDPOINT_BACKEND_AUTH = '/platform/uaano/oauth/token' const ENDPOINT_BACKEND_VALIDATE = '/platform/uaano/oauth/validate' +// Please, reader, fix this with proper environment variable management before deploying (!) +const MOCK_ENDPOINT_BACKEND = true -export default Object.freeze({ +module.exports = Object.freeze({ + APP, + API, + BASE_API, + SESS_KEY, + COOKIE_JWT, + SHOW_EXAMPLES, + AXIOS_DEFAULT_TIMEOUT, HOST, PORT, + LB_ADDR, ENDPOINT_BACKEND_AUTH, ENDPOINT_BACKEND_VALIDATE, - LB_ADDR, - ...consts + MOCK_ENDPOINT_BACKEND }) diff --git a/server/utils/helpers.js b/server/utils/helpers.js index 4019859e..5a3425e4 100644 --- a/server/utils/helpers.js +++ b/server/utils/helpers.js @@ -1,16 +1,16 @@ -import axios from 'axios' -import querystring from 'querystring' -import consts from '../utils/consts' -import jwtDecode from 'jwt-decode' +const axios = require('axios') +const querystring = require('querystring') +const consts = require('../utils/consts') +const jwtDecode = require('jwt-decode') -export const decode = token => { +const decode = token => { return token ? jwtDecode(token) : null } /** * Handle possibility where token endpoint, at exp returns seconds instead of ยต seconds */ -export const handleTokenExp = exp => { +const handleTokenExp = exp => { let out = exp const milliseconds = new Date().getTime() @@ -46,7 +46,7 @@ export const handleTokenExp = exp => { * All of this is done when you set your own LB_ADDR environment setup * to point to your own API. */ -export const createRequest = async (method, url, requestConfig) => { +const createRequest = async (method, url, requestConfig) => { const { payload = null, ...restOfRequestConfig @@ -68,7 +68,7 @@ export const createRequest = async (method, url, requestConfig) => { return Promise.resolve(data) } -export const getUserData = async (token) => { +const getUserData = async (token) => { const userinfo = [ 'DisplayName', 'PreferredLanguage', @@ -93,3 +93,10 @@ export const getUserData = async (token) => { return Promise.resolve(body) } + +module.exports = { + decode, + handleTokenExp, + createRequest, + getUserData +} diff --git a/server/utils/translator.js b/server/utils/translator.js index e5b153bb..606286a9 100644 --- a/server/utils/translator.js +++ b/server/utils/translator.js @@ -21,7 +21,7 @@ class Translator { } } -export default (locale) => { +module.exports = (locale) => { let fallbackLocale = 'en' let messages = {} try {