Skip to content

Commit

Permalink
add console to login component
Browse files Browse the repository at this point in the history
  • Loading branch information
adesege committed Nov 15, 2017
1 parent 3a14ec1 commit a5d0a96
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 49 deletions.
3 changes: 2 additions & 1 deletion client/.babelrc
@@ -1,3 +1,4 @@
{
"presets": ["env", "stage-0", "react"]
"presets": ["es2015", "react"],
"plugins": ["transform-object-rest-spread", "transform-es2015-destructuring"]
}
4 changes: 2 additions & 2 deletions client/config/webpack.common.js
Expand Up @@ -63,11 +63,11 @@ module.exports = {
module: {
rules: [
{
test: /\.jsx?$/,
test: /\.(js|jsx)?$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['env', 'stage-0', 'react']
presets: ['es2015', 'react']
}
},
{
Expand Down
8 changes: 6 additions & 2 deletions client/config/webpack.prod.js
@@ -1,4 +1,5 @@
const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const MinifyPlugin = require('babel-minify-webpack-plugin');
const babelMinify = require('babel-preset-minify');
Expand Down Expand Up @@ -47,14 +48,17 @@ module.exports = merge(common, {
]
},
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(),
extractSass,
new MinifyPlugin({
removeConsole: true,
removeDebugger: true
}, {
comments: true,
comments: false,
babel: babelCore,
minifyPreset: babelMinify
minifyPreset: babelMinify,
booleans: true,
keepFnName: true
})
],
});
90 changes: 64 additions & 26 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions client/package.json
Expand Up @@ -8,8 +8,11 @@
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-minify-webpack-plugin": "^0.2.0",
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.10",
"babel-preset-env": "^1.6.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-minify": "^0.2.0",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Books/ViewBooks/index.jsx
Expand Up @@ -41,7 +41,7 @@ class ViewBooks extends React.Component {
* @returns {void}
* @memberof ViewBooks
*/
componentDidMount = () => {
componentDidMount() {
const { params } = this.props;
this.props.getBook({ id: params.id });
this.props.getBorrowedBookAction(this.state.borrowBook);
Expand Down
1 change: 1 addition & 0 deletions client/src/components/homepage/login/Login.jsx
Expand Up @@ -35,6 +35,7 @@ class Login extends React.Component {
this.onSubmit = this.onSubmit.bind(this);
this.onGoogleCallback = this.onGoogleCallback.bind(this);
this.onFacebookCallback = this.onFacebookCallback.bind(this);
this.onGoogleFailure = this.onGoogleFailure.bind(this);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions server/src/api/v1/routes/index.js
Expand Up @@ -44,8 +44,8 @@ router.route('/users/:userId')
.put(authMiddleware, UserClass.updateUser);

router.route('/books')
.post(authMiddleware, BookClass.create)
.get(authMiddleware, BookClass.get);
.get(authMiddleware, BookClass.get)
.post(authMiddleware, BookClass.create);

router.route('/notifications')
.get(authMiddleware, adminMiddleware, NotificationClass.get);
Expand Down
19 changes: 19 additions & 0 deletions server/src/app/app.js
Expand Up @@ -12,4 +12,23 @@ export default (app) => {
app.engine('.html', renderFile);

app.use(routes);


// catch 404 and forward to error handler
app.use((req, res, next) => {
const err = new Error('Not Found');
err.status = 404;
next(err);
});

// error handler
app.use((err, req, res) => {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};

// render the error page
res.status(err.status || 500);
res.render('error');
});
};
2 changes: 1 addition & 1 deletion server/src/app/routes/index.js
Expand Up @@ -4,6 +4,6 @@ const router = express.Router();

router.get('/test', (_, res) => res.send({ message: 'Test passed' }));

router.get('*', (_, res) => res.render('index.html')); // pipe template/index.html to view
router.get(/^((?!(\/api\/v[0-9]\/)).)*$/, (req, res) => res.render('index.html')); // pipe template/index.html to view

export default router;
33 changes: 19 additions & 14 deletions server/src/express.js
@@ -1,7 +1,7 @@
import express from 'express';
import path from 'path';
import dotEnv from 'dotenv';
import expressApiVersioning from 'express-api-versioning';
import fs from 'fs';
import App from './app/app';

/* istanbul ignore next */
Expand All @@ -22,21 +22,26 @@ app
.send({ message: 'Welcome to Hello-Books api!' })
);

app.use(expressApiVersioning({
apiPath: path.join(__dirname, './api'), // absolute path to the api directory
test: /\/api\/(v[0-9]+).*/, // regular expression to get the version number from the url
entryPoint: 'app.js', // entry point exports a function which takes an instance of express as parameter.
instance: app // passes an instance of express to the entry point
}, (error, req, res, next) => {
if (error && error.code === 104) {
app.use((req, res, next) => {
let version = req.url.match(/\/api\/(v[0-9]+).*/);
if (version) {
version = version[1] || '';
if (version !== '') {
const appPath = path.join(__dirname, `./api/${version}/app.js`);
if (!fs.existsSync(appPath)) {
return res.status(404).send({
message: 'It\'s not us. Sorry, we can\'t find this endpoint'
});
}
/* eslint-disable global-require, import/no-dynamic-require */
const routes = require(appPath);
routes.default(app);
}
} else {
App(app);
} else if (error && error.code !== 104) {
return res.status(404).send({
message: 'It\'s not us. Sorry, we can\'t find this endpoint'
});
}
next(); // calls the next middleware
}));
next();
});

export default app;

0 comments on commit a5d0a96

Please sign in to comment.