Skip to content

Commit

Permalink
chore (Heroku build): Pushing to Heroku to test production builds
Browse files Browse the repository at this point in the history
- Production store implemented and can be accessed in production environment

- Removed global variable from code base by using browser:true in eslint

- Assigned api docs to /api-docs, static page

- Production environment defined

- webpack.config modified for production environment

- Refactored package.json to serve up start scripts

- Served the index.html to the app.js

- Edited procfile to use dist

chore (Heroku build): Fixed heroku build by fixing tests

- Reinstalled bcrypt to adhere with new node update.

- Refactored tests and seed files

- Introduced a file to order test
  • Loading branch information
Benny Ogidan authored and Benny Ogidan committed Oct 27, 2017
1 parent 8bb3bfa commit ea22347
Show file tree
Hide file tree
Showing 24 changed files with 248 additions and 257 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
82 changes: 47 additions & 35 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,37 +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
}
}]
},
"settings": {
"import/resolver": "node"
}
"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
6 changes: 3 additions & 3 deletions client/src/app/store/configStore.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const store = createStore(
);


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: 5 additions & 2 deletions client/src/app/store/configStore.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import configDev from './configStore.dev';
import configProd from './configStore.prod';

if (process.env.NODE_ENV === 'production') {
module.exports = require('./configStore.prod');
module.exports = configProd;
} else {
module.exports = require('./configStore.dev');
module.exports = configDev;
}
10 changes: 5 additions & 5 deletions client/src/app/store/configStore.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import thunk from 'redux-thunk';
import setAuthorizationToken from '../utils/setAuthorizationToken';
import { setCurrentUser } from '../actions/auth';
import rootReducer from '../reducers/rootReducers';
import { loadState, saveState } from '../utils/Localsave';
import { saveState } from '../utils/Localsave';

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


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 ea22347

Please sign in to comment.