Skip to content

Commit

Permalink
Merge pull request #3 from IamMohaiminul/refurbish
Browse files Browse the repository at this point in the history
Refurbish MERNjs
  • Loading branch information
IamMohaiminul authored Oct 6, 2020
2 parents 230625f + a8c6549 commit 43601e3
Show file tree
Hide file tree
Showing 77 changed files with 25,996 additions and 1,466 deletions.
5 changes: 1 addition & 4 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"presets": [
"env",
"react"
]
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
NODE_ENV=development
PORT=3000
API_URL=http://127.0.0.1:3000/api
MONGO_URL=mongodb://127.0.0.1:27017/MERNjs
JWT_SECRET=MERNjsJsonWebTokenSecret
JWT_EXPIRES=1h
MORGAN_FMT=dev
23 changes: 23 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"env": {
"browser": true,
"es2020": true
},
"extends": ["eslint:recommended", "plugin:react/recommended", "airbnb", "prettier"],
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 11,
"sourceType": "module"
},
"plugins": ["react"],
"rules": {
"no-console": "off",
"no-underscore-dangle": ["error", { "allow": ["_id", "_createdBy"] }],
"no-param-reassign": ["error", { "props": true, "ignorePropertyModificationsFor": ["req", "res", "err"] }],
"import/no-extraneous-dependencies": ["error", { "peerDependencies": true }],
"react/forbid-prop-types": ["error", { "forbid": ["any"] }],
"jsx-a11y/label-has-associated-control": ["error", { "assert": "either" }]
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Dependency directories
node_modules

# Environment variables
.env

# Build/Generate directories
build
dist
Expand Down
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 120
}
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2017 Muhammad Mohaiminul Islam
Copyright (c) 2020 Muhd Mohaiminul Islam

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
98 changes: 63 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
<img src="public/images/mernjs.png" height="128" />
<img src="public/images/logo.png" height="128" />

MERNjs is a full-stack JavaScript open-source solution, which provides a solid starting point for [MongoDB](http://www.mongodb.org/), [ExpressJS](http://expressjs.com/), [ReactJS](http//facebook.github.io/react/) and [NodeJS](http://www.nodejs.org/) based applications. The idea is to solve the common issues with connecting those frameworks, build a robust framework to support daily development needs, and help developers use better practices while working with popular JavaScript components.
MERNjs is an open-source full-stack JavaScript solution, which provides a solid starting point for [MongoDB](http://www.mongodb.org/), [ExpressJS](http://expressjs.com/), [ReactJS](https://reactjs.org/) and [NodeJS](http://www.nodejs.org/) based applications. The idea is to solve the common issues with connecting those frameworks, build a robust framework to support daily development needs, and help developers use better practices while working with popular JavaScript components.

## Before You Begin
Before you begin we recommend you read about the basic building blocks that assemble a MERNjs application:
* MongoDB - Go through [MongoDB Official Website](http://mongodb.org/) and proceed to their [Official Manual](http://docs.mongodb.org/manual/), which should help you understand NoSQL and MongoDB better.
* Express - The best way to understand express is through its [Official Website](http://expressjs.com/), which has a [Getting Started](http://expressjs.com/starter/installing.html) guide, as well as an [ExpressJS](http://expressjs.com/en/guide/routing.html) guide for general express topics.
* ReactJS - React's [Official Website](http//facebook.github.io/react/) is a great starting point.
* Node.js - Start by going through [Node.js Official Website](http://nodejs.org/) which should get you going with the Node.js platform in no time.

Before we begin, recommend to read about the basic building blocks that assemble a MERNjs application:

- MongoDB - Go through [MongoDB Official Website](http://mongodb.org/) and proceed to their [Official Manual](http://docs.mongodb.org/manual/), which should help you understand NoSQL and MongoDB better.
- Express - The best way to understand express is through its [Official Website](http://expressjs.com/), which has a [Getting Started](http://expressjs.com/starter/installing.html) guide, as well as an [ExpressJS](http://expressjs.com/en/guide/routing.html) guide for general express topics.
- ReactJS - React's [Official Website](http//facebook.github.io/react/) is a great starting point.
- Node.js - Start by going through [Node.js Official Website](http://nodejs.org/) which should get you going with the Node.js platform in no time.

## Prerequisites
Make sure you have installed all of the following prerequisites on your development machine:
* Git - [Download & Install Git](https://git-scm.com/downloads). OSX and Linux machines typically have this already installed.
* Node.js - [Download & Install Node.js](https://nodejs.org/en/download/) and the npm package manager. If you encounter any problems, you can also use this [GitHub Gist](https://gist.github.com/isaacs/579814) to install Node.js.
* MongoDB - [Download & Install MongoDB](http://www.mongodb.org/downloads), and make sure it's running on the default port (27017).

Make sure we have installed all of the following prerequisites on our development machine:

- Git - [Download & Install Git](https://git-scm.com/downloads). OSX and Linux machines typically have this already installed.
- Node.js - [Download & Install Node.js](https://nodejs.org/en/download/) and the npm package manager. If you encounter any problems, you can also use this [GitHub Gist](https://gist.github.com/isaacs/579814) to install Node.js.
- MongoDB - [Download & Install MongoDB](http://www.mongodb.org/downloads), and make sure it's running on the default port (27017).

## Downloading MERNjs
Currently there is a single way you can get the MERNjs boilerplate:

Currently there is a single way that we can get the MERNjs boilerplate:

### Cloning The GitHub Repository

The recommended way to get MERNjs is to use git to directly clone the MERNjs repository:

```bash
Expand All @@ -27,43 +33,65 @@ $ git clone https://github.com/IamMohaiminul/MERNjs MERNjs

This will clone the latest version of the MERNjs repository to a **MERNjs** folder.

## Running Your Application
To run your application follow this steps.
###### To install all dependencies
## Run our Application

To run our application follow this steps.

_Note: Before start the process, rename `.env.example` to `.env` and configure the environment variables._

###### To install the dependencies

```sh
// both dependencies and devDependencies
$ npm install
```
###### To start application

###### To build the application

```sh
// build the application
// build both server and client
$ npm run build

// start the application (without debug mode)
$ npm start
// start the application (with debug mode)
$ npm run debug
// build only server
$ npm run build:server

// build only client
$ npm run build:client
```
###### To live changes of application (not for production environment)

###### To start the application

```sh
// live changes of client side
$ npm run live:client
// without debug mode
$ npm start

// live changes of server side (without debug mode)
$ npm run live:server
// live changes of server side (with debug mode)
$ npm run live:server:debug
// with debug mode
$ npm run debug
```
*Note: Please make sure your MongoDB is running.*

Your application should run on port 3000 with the *default (development)* environment configuration, so in your browser just go to [http://127.0.0.1:3000/](http://127.0.0.1:3000/) for Client App, [http://127.0.0.1:3000/admin](http://127.0.0.1:3000/admin) for Admin App & [http://127.0.0.1:3000/api](http://127.0.0.1:3000/api) for RESTful APIs.
###### To watch the live changes of application

###### Default Admin User
```sh
Full Name: Administrator
Email: admin@mail.com
Password: admin
Role: Administrator
// watch both server and client
$ npm run watch

// watch only server
$ npm run watch:server

// watch only client
$ npm run watch:client
```

_Note: Please make sure our MongoDB is running._

###### Running application endpoints

Our application should run on port `3000` based on the environment configuration.

- Client App: [http://127.0.0.1:3000](http://127.0.0.1:3000)
- Admin App: [http://127.0.0.1:3000/admin](http://127.0.0.1:3000/admin)
- RESTful APIs: [http://127.0.0.1:3000/api](http://127.0.0.1:3000/api)

## License

[The MIT License](LICENSE)
59 changes: 26 additions & 33 deletions admin/auth/actions/login.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,29 @@
import axios from 'axios';

/*
* Get all user
*/
export const loginUser = ((object, callback) => {
try {
return function (dispatch) {
dispatch({ type: 'AUTH_LOGIN_REQUEST' });
axios.post('auth', object)
.then((response) => {
dispatch({
type: 'AUTH_LOGIN_SUCCESS',
payload: response.data,
});
localStorage.setItem('token', response.data.data.token);
localStorage.setItem('email', response.data.data.email);
if (typeof callback === 'function') {
callback(null, response.data);
}
})
.catch((error) => {
dispatch({ type: 'AUTH_LOGIN_FAILURE' });
if (typeof callback === 'function') {
callback(error.response.data, null);
}
});
};
} catch (e) {
return res.status(500).json({
success: false,
message: 'Error in loginUser',
error: e,
const loginUser = (object, callback) => (dispatch) => {
dispatch({
type: 'AUTH_LOGIN_REQUEST',
});
axios
.post('/auth', object)
.then((response) => {
dispatch({
type: 'AUTH_LOGIN_SUCCESS',
payload: response.data,
});
localStorage.setItem('token', response.data.data.token);
localStorage.setItem('email', response.data.data.email);
if (typeof callback === 'function') {
callback(null, response.data);
}
})
.catch((err) => {
console.log('auth_err: ', err);
dispatch({ type: 'AUTH_LOGIN_FAILURE' });
if (typeof callback === 'function') {
callback(err.response.data, null);
}
});
}
});
};

export default loginUser;
52 changes: 21 additions & 31 deletions admin/auth/actions/register.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
import axios from 'axios';

/*
* Get all user
*/
export const registerUser = ((object, callback) => {
try {
return function (dispatch) {
dispatch({ type: 'AUTH_REGISTER_REQUEST' });
axios.post('auth/register', object)
.then((response) => {
dispatch({
type: 'AUTH_REGISTER_SUCCESS',
payload: response.data,
});
if (typeof callback === 'function') {
callback(null, response.data);
}
})
.catch((error) => {
dispatch({ type: 'AUTH_REGISTER_FAILURE' });
if (typeof callback === 'function') {
callback(error.response.data, null);
}
});
};
} catch (e) {
return res.status(500).json({
success: false,
message: 'Error in registerUser',
error: e,
const registerUser = (object, callback) => (dispatch) => {
dispatch({ type: 'AUTH_REGISTER_REQUEST' });
axios
.post('/auth/register', object)
.then((response) => {
dispatch({
type: 'AUTH_REGISTER_SUCCESS',
payload: response.data,
});
if (typeof callback === 'function') {
callback(null, response.data);
}
})
.catch((error) => {
dispatch({ type: 'AUTH_REGISTER_FAILURE' });
if (typeof callback === 'function') {
callback(error.response.data, null);
}
});
}
});
};

export default registerUser;
Loading

0 comments on commit 43601e3

Please sign in to comment.