Skip to content

Commit

Permalink
fix: server failure
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkdo committed Apr 24, 2018
1 parent bf13342 commit 7d36d39
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 44 deletions.
10 changes: 3 additions & 7 deletions client/utils/consts.js
Original file line number Diff line number Diff line change
@@ -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

This comment has been minimized.

Copy link
@renoirb

renoirb May 29, 2018

Collaborator

Hey @clarkdo, I realized lately how I messed up consts with regards to process.env.

In my local fork, things break. And I see here how you're doing it.

I'm going to review how config work, see how what you've done works/how to inject at runtime, and make sure all toggles work properly.

})
9 changes: 0 additions & 9 deletions client/utils/consts.json

This file was deleted.

1 change: 1 addition & 0 deletions server/api/routes-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions server/api/routes-menu.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down
36 changes: 19 additions & 17 deletions server/utils/consts.js
Original file line number Diff line number Diff line change
@@ -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`
Expand All @@ -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
})
23 changes: 15 additions & 8 deletions server/utils/helpers.js
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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',
Expand All @@ -93,3 +93,10 @@ export const getUserData = async (token) => {

return Promise.resolve(body)
}

module.exports = {
decode,
handleTokenExp,
createRequest,
getUserData
}
2 changes: 1 addition & 1 deletion server/utils/translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Translator {
}
}

export default (locale) => {
module.exports = (locale) => {
let fallbackLocale = 'en'
let messages = {}
try {
Expand Down

0 comments on commit 7d36d39

Please sign in to comment.