Skip to content

Commit

Permalink
chore (Deployment of heroku)
Browse files Browse the repository at this point in the history
- Refactored test codes
- Added a webpack.prod.config.js
  • Loading branch information
Benny Ogidan authored and Benny Ogidan committed Oct 27, 2017
1 parent 62fd9d4 commit 35fb9ad
Show file tree
Hide file tree
Showing 26 changed files with 471 additions and 338 deletions.
11 changes: 11 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
JWT_SECRET=sampleJWT
DBUSERNAME=sampledb
DBPASSWORD=password
DB=sampledb
DBADDRESS=SampleIpaddress
DBDIALECT=Sampledialect
TESTDB=sampletestdb
ISBNRANDOM_MIN_ID =test_random_id
ISBNRANDOM_MAX_ID=test_random_id
DATABASE_URL=databaseurl
NODE_ENV=environment
79 changes: 47 additions & 32 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,34 +1,49 @@
{
"root": true,
"extends": "airbnb-base",
"env": {
"node": true,
"es6": true,
"mocha": true
},
"rules": {
"one-var": 0,
"one-var-declaration-per-line": 0,
"new-cap": 0,
"consistent-return": 0,
"no-param-reassign": 0,
"comma-dangle": 0,
"curly": ["error", "multi-line"],
"prefer-destructuring": ["error", {"object": false,"array": false}],
"import/no-unresolved": [2, { "commonjs": true }],
"no-shadow": ["error", { "allow": ["req", "res", "err"] }],
"valid-jsdoc": ["error", {
"requireReturn": true,
"requireReturnType": true,
"requireParamDescription": false,
"requireReturnDescription": true
}],
"require-jsdoc": ["error", {
"require": {
"FunctionDeclaration": true,
"MethodDefinition": true,
"ClassDeclaration": true
}
}]
}
"root": true,
"extends": "airbnb-base",
"env": {
"browser": true,
"jquery": true,
"node": true,
"es6": true,
"mocha": true
},
"globals": {
"describe": true,
"expect": true
},
"rules": {
"one-var": 0,
"one-var-declaration-per-line": 0,
"new-cap": 0,
"consistent-return": 0,
"no-param-reassign": 0,
"comma-dangle": 0,
"curly": [ "error", "multi-line" ],
"prefer-destructuring": [ "error", { "object": false, "array": false } ],
"import/no-unresolved": [ 2, { "commonjs": true } ],
"no-shadow": [ "error", { "allow": [ "req", "res", "err" ] } ],
"valid-jsdoc": [
"error",
{
"requireReturn": true,
"requireReturnType": true,
"requireParamDescription": false,
"requireReturnDescription": true
}
],
"require-jsdoc": [
"error",
{
"require": {
"FunctionDeclaration": true,
"MethodDefinition": true,
"ClassDeclaration": true
}
}
]
},
"settings": {
"import/resolver": "node"
}
}
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ before_script:
- npm install -g sequelize
- psql -c 'drop database if exists travis;' -U postgres
- psql -c 'create database travis;' -U postgres
- NODE_ENV=test && npm run test:db
script:
- npm test

Expand Down
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: node ./server/dist/bin/www.js
web: npm run start
8 changes: 4 additions & 4 deletions client/src/app/actions/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export const login = credentials => dispatch => api
dispatch(signInUserFailure(user));
return Promise.reject(token);
}
global.localStorage.setItem('token', token);
global.localStorage.setItem('username', username);
localStorage.setItem('token', token);
localStorage.setItem('username', username);

setAuthorizationToken(token);
dispatch(userLoggedIn(user.data));
Expand All @@ -88,8 +88,8 @@ export const login = credentials => dispatch => api
* @param {*} dispatch
*/
export const logout = () => (dispatch) => {
global.localStorage.removeItem('token');
global.localStorage.removeItem('username');
localStorage.removeItem('token');
localStorage.removeItem('username');
setAuthorizationToken(false);
dispatch(userLoggedOut());
};
Expand Down
8 changes: 8 additions & 0 deletions client/src/app/store/configStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import configDev from './configStore.dev';
import configProd from './configStore.prod';

if (process.env.NODE_ENV === 'production') {
module.exports = configProd;
} else {
module.exports = configDev;
}
29 changes: 29 additions & 0 deletions client/src/app/store/configStore.prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import jwtdecode from 'jwt-decode';
import throttle from 'lodash/throttle';

import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import setAuthorizationToken from '../utils/setAuthorizationToken';
import { setCurrentUser } from '../actions/auth';
import rootReducer from '../reducers/rootReducers';
import { saveState } from '../utils/Localsave';

const initialState = {};
const store = createStore(
rootReducer,
initialState,
(applyMiddleware(thunk))
);


if (localStorage.token) {
setAuthorizationToken(localStorage.token);
store.dispatch(setCurrentUser(jwtdecode(localStorage.token)));
}

store.subscribe(throttle(() => {
saveState(store.getState());
}), 1000);


export default store;
6 changes: 3 additions & 3 deletions client/src/app/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ const store = createStore(
// const store = composeWithDevTools( applyMiddleware(createLogger(), thunk),
// autoRehydrate() )(createStore)(rootReducer);

if (global.localStorage.token) {
setAuthorizationToken(global.localStorage.token);
store.dispatch(setCurrentUser(jwtdecode(global.localStorage.token)));
if (localStorage.token) {
setAuthorizationToken(localStorage.token);
store.dispatch(setCurrentUser(jwtdecode(localStorage.token)));
}

store.subscribe(throttle(() => {
Expand Down
7 changes: 3 additions & 4 deletions client/src/app/utils/Localsave.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/*
eslint-disable no-console
*/
export const saveState = (state) => {
try {
// localStorage.setItem('username', state.user.user.username || null);
//let serializedState;
const serializedState = JSON.stringify(state);
localStorage.setItem('state', serializedState);


} catch (e) {
console.log(e);
}
Expand Down
Loading

0 comments on commit 35fb9ad

Please sign in to comment.