Skip to content

Commit

Permalink
✨ mockbee 2.0: add CRA templates (#74)
Browse files Browse the repository at this point in the history
* ✨ mockbee 2.0: add CRA templates

* feat: update video library cra template

* fix: ecommerce app related errors and templates

* fix: ecomm errors

* downgrade the version
  • Loading branch information
sohamsshah authored Mar 14, 2022
1 parent 525059a commit 64120da
Show file tree
Hide file tree
Showing 170 changed files with 9,197 additions and 1,711 deletions.
12 changes: 12 additions & 0 deletions apps/cra-template-mockbee-ecommerce/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "cra-template-mockbee-ecommerce",
"version": "1.0.0",
"main": "template.json",
"files": [
"template",
"template.json"
],
"engines": {
"node": ">=14"
}
}
26 changes: 26 additions & 0 deletions apps/cra-template-mockbee-ecommerce/template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"package": {
"dependencies": {
"dayjs": "^1.10.7",
"miragejs": "^0.1.41",
"uuid": "^8.3.2",
"jwt-decode": "^3.1.2",
"jwt-encode": "^1.0.1",
"mockman-js": "^1.0.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"browserslist": {
"production": [">0.2%", "not dead", "not op_mini all"],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
}
3 changes: 3 additions & 0 deletions apps/cra-template-mockbee-ecommerce/template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## E-Commerce Backend

This folder contains the Mock Backend created for E-Commerce App. It contains different API end-points and database configuration for building E-Commerce; so that you can focus on building Frontend.
25 changes: 25 additions & 0 deletions apps/cra-template-mockbee-ecommerce/template/gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
.eslintcache

npm-debug.log*
yarn-debug.log*
yarn-error.log*
Binary file not shown.
43 changes: 43 additions & 0 deletions apps/cra-template-mockbee-ecommerce/template/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions apps/cra-template-mockbee-ecommerce/template/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
51 changes: 51 additions & 0 deletions apps/cra-template-mockbee-ecommerce/template/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
.App {
text-align: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}

.App-header {
background-color: #22201c;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
color: white;
}

.App-link {
color: #61dafb;
}

.brand-title {
font-size: 3rem;
color: #d9d9d9;
}

.brand-title span {
color: #ffde59;
}

.brand-description {
font-size: 1.4rem;
}

.links {
display: flex;
}

.links a {
color: #d9d9d9;
font-size: 1.2rem;
margin: 1rem;
}
43 changes: 43 additions & 0 deletions apps/cra-template-mockbee-ecommerce/template/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import "./App.css";
import logo from "./logo.png";

function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} alt="mockBee logo" width="180" height="180" />
<h1 className="brand-title">
Welcome to <span>mockBee!</span>
</h1>
<p className="brand-description">
Get started by editing <code>src/App.js</code>
</p>
<div className="links">
<a
href="https://mockbee.netlify.app/"
target="_blank"
rel="noreferrer"
>
Explore mockBee
</a>
<a
href="https://mockbee.netlify.app/docs/api/introduction"
target="_blank"
rel="noreferrer"
>
API Documentation
</a>
<a
href="https://github.com/neogcamp/mockBee"
target="_blank"
rel="noreferrer"
>
Contribute
</a>
</div>
</header>
</div>
);
}

export default App;
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { v4 as uuid } from "uuid";
import { Response } from "miragejs";
import { formatDate } from "../utils/authUtils";
const sign = require("jwt-encode");
/**
* All the routes related to Auth are present here.
* These are Publicly accessible routes.
* */

/**
* This handler handles user signups.
* send POST Request at /api/auth/signup
* body contains {firstName, lastName, email, password}
* */

export const signupHandler = function (schema, request) {
const { email, password, ...rest } = JSON.parse(request.requestBody);
try {
// check if email already exists
const foundUser = schema.users.findBy({ email });
if (foundUser) {
return new Response(
422,
{},
{
errors: ["Unprocessable Entity. Email Already Exists."],
}
);
}
const _id = uuid();
const newUser = {
_id,
email,
password,
createdAt: formatDate(),
updatedAt: formatDate(),
...rest,
cart: [],
wishlist: [],
};
const createdUser = schema.users.create(newUser);
const encodedToken = sign({ _id, email }, process.env.REACT_APP_JWT_SECRET);
return new Response(201, {}, { createdUser, encodedToken });
} catch (error) {
return new Response(
500,
{},
{
error,
}
);
}
};

/**
* This handler handles user login.
* send POST Request at /api/auth/login
* body contains {email, password}
* */

export const loginHandler = function (schema, request) {
const { email, password } = JSON.parse(request.requestBody);
try {
const foundUser = schema.users.findBy({ email });
if (!foundUser) {
return new Response(
404,
{},
{ errors: ["The email you entered is not Registered. Not Found error"] }
);
}
if (password === foundUser.password) {
const encodedToken = sign(
{ _id: foundUser._id, email },
process.env.REACT_APP_JWT_SECRET
);
foundUser.password = undefined;
return new Response(200, {}, { foundUser, encodedToken });
}
new Response(
401,
{},
{
errors: [
"The credentials you entered are invalid. Unauthorized access error.",
],
}
);
} catch (error) {
return new Response(
500,
{},
{
error,
}
);
}
};
Loading

0 comments on commit 64120da

Please sign in to comment.