├── .prettierrc.json
├── nodemon.json
├── .prettierignore
├── .eslintignore
├── client
├── src
│ ├── pages
│ │ ├── Apps
│ │ │ ├── index.js
│ │ │ └── Apps.js
│ │ ├── Logs
│ │ │ ├── index.js
│ │ │ └── Logs.js
│ │ └── Login
│ │ │ ├── index.js
│ │ │ ├── Login.stories.js
│ │ │ └── Login.js
│ ├── components
│ │ ├── Button
│ │ │ ├── index.js
│ │ │ ├── Button.js
│ │ │ └── Button.stories.js
│ │ ├── Header
│ │ │ ├── index.js
│ │ │ ├── Header.stories.js
│ │ │ └── Header.js
│ │ ├── LogsTable
│ │ │ ├── index.js
│ │ │ ├── LogsTable.js
│ │ │ └── LogsTable.stories.js
│ │ ├── ErrorButton
│ │ │ ├── index.js
│ │ │ ├── ErrorButton.js
│ │ │ └── ErrorButton.stories.js
│ │ ├── InfoButton
│ │ │ ├── index.js
│ │ │ ├── InfoButton.js
│ │ │ └── InfoButton.stories.js
│ │ ├── LevelFilters
│ │ │ ├── index.js
│ │ │ ├── LevelFilters.stories.js
│ │ │ └── LevelFilters.js
│ │ ├── LogsTableRow
│ │ │ ├── index.js
│ │ │ └── LogsTableRow.js
│ │ ├── WarningButton
│ │ │ ├── index.js
│ │ │ ├── WarningButton.js
│ │ │ └── WarningButton.stories.js
│ │ └── LanguageSelector
│ │ │ ├── index.js
│ │ │ └── LanguageSelector.js
│ ├── assets
│ │ ├── logo.png
│ │ ├── direction.svg
│ │ ├── flow.svg
│ │ ├── code-brackets.svg
│ │ ├── comments.svg
│ │ ├── repo.svg
│ │ ├── plugin.svg
│ │ ├── stackalt.svg
│ │ └── colors.svg
│ ├── App.test.js
│ ├── api
│ │ ├── logs.js
│ │ └── auth.js
│ ├── setupTests.js
│ ├── i18n
│ │ ├── en.json
│ │ ├── de.json
│ │ └── context.js
│ ├── index.js
│ ├── hooks
│ │ ├── useCookie.js
│ │ └── useFetch.js
│ ├── App.js
│ ├── GlobalStyles.js
│ └── serviceWorker.js
├── public
│ ├── favicon.ico
│ ├── logo192.png
│ ├── logo512.png
│ ├── robots.txt
│ ├── fonts
│ │ ├── Cascadia.eot
│ │ ├── Cascadia.otf
│ │ ├── Cascadia.ttf
│ │ └── Cascadia.woff
│ ├── manifest.json
│ └── index.html
├── .storybook
│ ├── main.js
│ └── preview.js
├── .gitignore
├── package.json
└── README.md
├── README.md
├── .eslintrc.json
├── lib
├── db.js
├── logsRouter.js
└── authRouter.js
├── .github
└── workflows
│ └── node.js.yml
├── LICENSE
├── server.js
├── .gitignore
└── package.json
/.prettierrc.json:
--------------------------------------------------------------------------------
1 | {}
2 |
--------------------------------------------------------------------------------
/nodemon.json:
--------------------------------------------------------------------------------
1 | {
2 | "ignore": ["client/*"]
3 | }
4 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | # Ignore artifacts:
2 | build
3 | coverage
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | build/
3 | storybook-static/
--------------------------------------------------------------------------------
/client/src/pages/Apps/index.js:
--------------------------------------------------------------------------------
1 | export { default } from "./Apps";
2 |
--------------------------------------------------------------------------------
/client/src/pages/Logs/index.js:
--------------------------------------------------------------------------------
1 | export { default } from "./Logs";
2 |
--------------------------------------------------------------------------------
/client/src/pages/Login/index.js:
--------------------------------------------------------------------------------
1 | export { default } from "./Login";
2 |
--------------------------------------------------------------------------------
/client/src/components/Button/index.js:
--------------------------------------------------------------------------------
1 | export { default } from "./Button";
2 |
--------------------------------------------------------------------------------
/client/src/components/Header/index.js:
--------------------------------------------------------------------------------
1 | export { default } from "./Header";
2 |
--------------------------------------------------------------------------------
/client/src/components/LogsTable/index.js:
--------------------------------------------------------------------------------
1 | export { default } from "./LogsTable";
2 |
--------------------------------------------------------------------------------
/client/src/components/ErrorButton/index.js:
--------------------------------------------------------------------------------
1 | export { default } from "./ErrorButton";
2 |
--------------------------------------------------------------------------------
/client/src/components/InfoButton/index.js:
--------------------------------------------------------------------------------
1 | export { default } from "./InfoButton";
2 |
--------------------------------------------------------------------------------
/client/src/components/LevelFilters/index.js:
--------------------------------------------------------------------------------
1 | export { default } from "./LevelFilters";
2 |
--------------------------------------------------------------------------------
/client/src/components/LogsTableRow/index.js:
--------------------------------------------------------------------------------
1 | export { default } from "./LogsTableRow";
2 |
--------------------------------------------------------------------------------
/client/src/components/WarningButton/index.js:
--------------------------------------------------------------------------------
1 | export { default } from "./WarningButton";
2 |
--------------------------------------------------------------------------------
/client/src/components/LanguageSelector/index.js:
--------------------------------------------------------------------------------
1 | export { default } from "./LanguageSelector";
2 |
--------------------------------------------------------------------------------
/client/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lmachens/logs/HEAD/client/public/favicon.ico
--------------------------------------------------------------------------------
/client/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lmachens/logs/HEAD/client/public/logo192.png
--------------------------------------------------------------------------------
/client/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lmachens/logs/HEAD/client/public/logo512.png
--------------------------------------------------------------------------------
/client/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/client/src/assets/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lmachens/logs/HEAD/client/src/assets/logo.png
--------------------------------------------------------------------------------
/client/public/fonts/Cascadia.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lmachens/logs/HEAD/client/public/fonts/Cascadia.eot
--------------------------------------------------------------------------------
/client/public/fonts/Cascadia.otf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lmachens/logs/HEAD/client/public/fonts/Cascadia.otf
--------------------------------------------------------------------------------
/client/public/fonts/Cascadia.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lmachens/logs/HEAD/client/public/fonts/Cascadia.ttf
--------------------------------------------------------------------------------
/client/public/fonts/Cascadia.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lmachens/logs/HEAD/client/public/fonts/Cascadia.woff
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | # cra-with-api
4 |
5 | Boilerplate for Create-React-App with an Express.js API
6 |
--------------------------------------------------------------------------------
/client/src/App.test.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { render } from "@testing-library/react";
3 | import App from "./App";
4 |
5 | test("renders App", () => {
6 | render();
7 | });
8 |
--------------------------------------------------------------------------------
/client/.storybook/main.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | stories: ["../src/**/*.stories.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
3 | addons: [
4 | "@storybook/addon-links",
5 | "@storybook/addon-essentials",
6 | "@storybook/preset-create-react-app",
7 | ],
8 | };
9 |
--------------------------------------------------------------------------------
/client/src/api/logs.js:
--------------------------------------------------------------------------------
1 | export const getLogs = async (filters) => {
2 | const queryParams = filters.map((filter) => `level=${filter}`).join("&");
3 | const response = await fetch(`/api/logs?${queryParams}`);
4 | const logs = await response.json();
5 | return logs;
6 | };
7 |
--------------------------------------------------------------------------------
/client/src/pages/Apps/Apps.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { useDictMessages } from "../../i18n/context";
3 |
4 | const Apps = () => {
5 | const dictMessages = useDictMessages();
6 |
7 | return
{dictMessages.comingSoon}
;
8 | };
9 |
10 | export default Apps;
11 |
--------------------------------------------------------------------------------
/client/src/components/InfoButton/InfoButton.js:
--------------------------------------------------------------------------------
1 | import styled from "@emotion/styled";
2 | import Button from "../Button";
3 |
4 | const InfoButton = styled(Button)`
5 | color: var(--info-color);
6 | `;
7 |
8 | InfoButton.displayName = "InfoButton";
9 |
10 | export default InfoButton;
11 |
--------------------------------------------------------------------------------
/client/src/setupTests.js:
--------------------------------------------------------------------------------
1 | // jest-dom adds custom jest matchers for asserting on DOM nodes.
2 | // allows you to do things like:
3 | // expect(element).toHaveTextContent(/react/i)
4 | // learn more: https://github.com/testing-library/jest-dom
5 | import "@testing-library/jest-dom/extend-expect";
6 |
--------------------------------------------------------------------------------
/client/src/pages/Login/Login.stories.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | import Login from "./Login";
4 |
5 | export default {
6 | title: "Login",
7 | component: Login,
8 | };
9 |
10 | const Template = (args) => ;
11 |
12 | export const Default = Template.bind({});
13 |
--------------------------------------------------------------------------------
/client/src/components/ErrorButton/ErrorButton.js:
--------------------------------------------------------------------------------
1 | import styled from "@emotion/styled";
2 | import Button from "../Button";
3 |
4 | const ErrorButton = styled(Button)`
5 | color: var(--error-color);
6 | `;
7 |
8 | ErrorButton.displayName = "ErrorButton";
9 |
10 | export default ErrorButton;
11 |
--------------------------------------------------------------------------------
/client/src/components/WarningButton/WarningButton.js:
--------------------------------------------------------------------------------
1 | import styled from "@emotion/styled";
2 | import Button from "../Button";
3 |
4 | const WarningButton = styled(Button)`
5 | color: var(--warning-color);
6 | `;
7 |
8 | WarningButton.displayName = "WarningButton";
9 |
10 | export default WarningButton;
11 |
--------------------------------------------------------------------------------
/client/src/components/Button/Button.js:
--------------------------------------------------------------------------------
1 | import styled from "@emotion/styled";
2 |
3 | const Button = styled.button`
4 | border: 1px solid currentColor;
5 | border-radius: 15px;
6 | background: none;
7 | padding: 0.3rem 0.6rem;
8 | filter: ${(props) => (props.inactive ? "grayscale(1)" : "none")};
9 | `;
10 |
11 | export default Button;
12 |
--------------------------------------------------------------------------------
/client/src/api/auth.js:
--------------------------------------------------------------------------------
1 | export const login = async (credentials) => {
2 | const response = await fetch("/api/login", {
3 | method: "POST",
4 | headers: {
5 | "Content-Type": "application/json",
6 | },
7 | body: JSON.stringify(credentials),
8 | });
9 |
10 | const account = await response.json();
11 | return account;
12 | };
13 |
--------------------------------------------------------------------------------
/client/src/i18n/en.json:
--------------------------------------------------------------------------------
1 | {
2 | "locale": "en",
3 | "messages": {
4 | "login": "Login",
5 | "emailPlaceholder": "What's your email?",
6 | "loading": "Loading...",
7 | "origin": "Origin",
8 | "createdAt": "Created At",
9 | "level": "Level",
10 | "message": "Message",
11 | "comingSoon": "Coming soon..."
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/client/src/i18n/de.json:
--------------------------------------------------------------------------------
1 | {
2 | "locale": "de",
3 | "messages": {
4 | "login": "Einloggen",
5 | "emailPlaceholder": "Wie ist deine E-Mail?",
6 | "loading": "Lade...",
7 | "origin": "Quelle",
8 | "createdAt": "Erstellt am",
9 | "level": "Level",
10 | "message": "Nachricht",
11 | "comingSoon": "In Entwicklung..."
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/client/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 | /storybook-static
14 |
15 | # misc
16 | .DS_Store
17 | .env.local
18 | .env.development.local
19 | .env.test.local
20 | .env.production.local
21 |
22 | npm-debug.log*
23 | yarn-debug.log*
24 | yarn-error.log*
25 |
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "browser": true,
4 | "commonjs": true,
5 | "es6": true,
6 | "node": true
7 | },
8 | "extends": [
9 | "react-app",
10 | "eslint:recommended",
11 | "plugin:react/recommended",
12 | "prettier"
13 | ],
14 | "parserOptions": {
15 | "ecmaFeatures": {
16 | "jsx": true
17 | },
18 | "ecmaVersion": 12,
19 | "sourceType": "module"
20 | },
21 | "rules": {}
22 | }
23 |
--------------------------------------------------------------------------------
/client/src/components/Button/Button.stories.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | import Button from "./Button";
4 |
5 | export default {
6 | title: "Button",
7 | component: Button,
8 | };
9 |
10 | const Template = (args) => ;
11 |
12 | export const Default = Template.bind({});
13 | Default.args = {
14 | children: "Default",
15 | };
16 |
17 | export const Disabled = Template.bind({});
18 | Disabled.args = {
19 | children: "Default",
20 | inactive: true,
21 | };
22 |
--------------------------------------------------------------------------------
/client/.storybook/preview.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import GlobalStyles from "../src/GlobalStyles";
3 | import { I18nProvider } from "../src/i18n/context";
4 |
5 | export const parameters = {
6 | actions: { argTypesRegex: "^on[A-Z].*" },
7 | };
8 |
9 | const AppDecorator = (Story, context) => {
10 | return (
11 |
12 |
13 |
14 |
15 | );
16 | };
17 |
18 | export const decorators = [AppDecorator];
19 |
--------------------------------------------------------------------------------
/client/src/components/InfoButton/InfoButton.stories.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | import InfoButton from "./InfoButton";
4 |
5 | export default {
6 | title: "Info Button",
7 | component: InfoButton,
8 | };
9 |
10 | const Template = (args) => ;
11 |
12 | export const Info = Template.bind({});
13 | Info.args = {
14 | children: "Info",
15 | };
16 |
17 | export const Disabled = Template.bind({});
18 | Disabled.args = {
19 | children: "Info",
20 | inactive: true,
21 | };
22 |
--------------------------------------------------------------------------------
/client/src/components/ErrorButton/ErrorButton.stories.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | import ErrorButton from "./ErrorButton";
4 |
5 | export default {
6 | title: "Error Button",
7 | component: ErrorButton,
8 | };
9 |
10 | const Template = (args) => ;
11 |
12 | export const Error = Template.bind({});
13 | Error.args = {
14 | children: "Error",
15 | };
16 |
17 | export const Disabled = Template.bind({});
18 | Disabled.args = {
19 | children: "Error",
20 | inactive: true,
21 | };
22 |
--------------------------------------------------------------------------------
/client/src/components/LanguageSelector/LanguageSelector.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { useI18n } from "../../i18n/context";
3 |
4 | const LanguageSelector = () => {
5 | const [dict, changeDict] = useI18n();
6 |
7 | return (
8 |
15 | );
16 | };
17 |
18 | export default LanguageSelector;
19 |
--------------------------------------------------------------------------------
/client/src/components/LevelFilters/LevelFilters.stories.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | import LevelFilters from "./LevelFilters";
4 |
5 | export default {
6 | title: "LevelFilters",
7 | component: LevelFilters,
8 | };
9 |
10 | const Template = (args) => ;
11 |
12 | export const AllActive = Template.bind({});
13 | AllActive.args = {
14 | filters: ["error", "warning", "info"],
15 | };
16 |
17 | export const OnlyError = Template.bind({});
18 | OnlyError.args = {
19 | filters: ["error"],
20 | };
21 |
--------------------------------------------------------------------------------
/client/src/components/WarningButton/WarningButton.stories.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | import WarningButton from "./WarningButton";
4 |
5 | export default {
6 | title: "Warning Button",
7 | component: WarningButton,
8 | };
9 |
10 | const Template = (args) => ;
11 |
12 | export const Warning = Template.bind({});
13 | Warning.args = {
14 | children: "Warning",
15 | };
16 |
17 | export const Disabled = Template.bind({});
18 | Disabled.args = {
19 | children: "Warning",
20 | inactive: true,
21 | };
22 |
--------------------------------------------------------------------------------
/lib/db.js:
--------------------------------------------------------------------------------
1 | const { MongoClient } = require("mongodb");
2 |
3 | let db = null;
4 | const connectDB = async () => {
5 | const client = await MongoClient.connect(process.env.MONGODB_URI, {
6 | useUnifiedTopology: true,
7 | });
8 |
9 | db = client.db(process.env.MONGODB_NAME);
10 | };
11 |
12 | const close = () => {
13 | return db.close();
14 | };
15 |
16 | const getCollection = (name) => {
17 | return db.collection(name);
18 | };
19 |
20 | exports.connectDB = connectDB;
21 | exports.close = close;
22 | exports.getCollection = getCollection;
23 |
--------------------------------------------------------------------------------
/client/src/index.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import ReactDOM from "react-dom";
3 | import App from "./App";
4 | import * as serviceWorker from "./serviceWorker";
5 |
6 | ReactDOM.render(
7 |
8 |
9 | ,
10 | document.getElementById("root")
11 | );
12 |
13 | // If you want your app to work offline and load faster, you can change
14 | // unregister() to register() below. Note this comes with some pitfalls.
15 | // Learn more about service workers: https://bit.ly/CRA-PWA
16 | serviceWorker.unregister();
17 |
--------------------------------------------------------------------------------
/client/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "CRA-With-API",
3 | "name": "CRA-With-API Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/client/src/hooks/useCookie.js:
--------------------------------------------------------------------------------
1 | import { useState, useCallback } from "react";
2 | import Cookies from "js-cookie";
3 |
4 | const useCookie = (cookieName) => {
5 | const [value, setValue] = useState(() => Cookies.get(cookieName) || null);
6 |
7 | const setCookie = useCallback(
8 | (newValue, options) => {
9 | Cookies.set(cookieName, newValue, options);
10 | setValue(newValue);
11 | },
12 | [cookieName]
13 | );
14 |
15 | const removeCookie = useCallback(() => {
16 | Cookies.remove(cookieName);
17 | setValue(null);
18 | }, [cookieName]);
19 |
20 | return [value, setCookie, removeCookie];
21 | };
22 |
23 | export default useCookie;
24 |
--------------------------------------------------------------------------------
/client/src/hooks/useFetch.js:
--------------------------------------------------------------------------------
1 | const { useState, useEffect } = require("react");
2 |
3 | const useAsync = (asyncFunc, params) => {
4 | const [data, setData] = useState(null);
5 | const [loading, setLoading] = useState(false);
6 | const [error, setError] = useState(null);
7 |
8 | useEffect(() => {
9 | const doCall = async () => {
10 | try {
11 | setLoading(true);
12 | setError(null);
13 | setData(null);
14 | const newData = await asyncFunc(params);
15 | setData(newData);
16 | } catch (error) {
17 | setError(error);
18 | } finally {
19 | setLoading(false);
20 | }
21 | };
22 |
23 | doCall();
24 | }, [asyncFunc, params]);
25 |
26 | return { data, loading, error };
27 | };
28 |
29 | export default useAsync;
30 |
--------------------------------------------------------------------------------
/client/src/components/LogsTable/LogsTable.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import PropTypes from "prop-types";
3 | import styled from "@emotion/styled";
4 | import { useDictMessages } from "../../i18n/context";
5 |
6 | const Table = styled.table`
7 | td {
8 | padding: 0.5rem 1rem;
9 | }
10 | `;
11 |
12 | const LogsTable = ({ children }) => {
13 | const dictMessages = useDictMessages();
14 |
15 | return (
16 |
17 |
18 |
19 | | {dictMessages.origin} |
20 | {dictMessages.createdAt} |
21 | {dictMessages.level} |
22 | {dictMessages.message} |
23 |
24 |
25 | {children}
26 |
27 | );
28 | };
29 |
30 | LogsTable.propTypes = {
31 | children: PropTypes.node,
32 | };
33 |
34 | export default LogsTable;
35 |
--------------------------------------------------------------------------------
/.github/workflows/node.js.yml:
--------------------------------------------------------------------------------
1 | # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3 |
4 | name: Node.js CI
5 |
6 | on:
7 | push:
8 | branches: [ master ]
9 | pull_request:
10 | branches: [ master ]
11 |
12 | jobs:
13 | build:
14 |
15 | runs-on: ubuntu-latest
16 |
17 | strategy:
18 | matrix:
19 | node-version: [10.x, 12.x, 14.x]
20 |
21 | steps:
22 | - uses: actions/checkout@v2
23 | - name: Use Node.js ${{ matrix.node-version }}
24 | uses: actions/setup-node@v1
25 | with:
26 | node-version: ${{ matrix.node-version }}
27 | - run: npm ci
28 | - run: npm run build --if-present
29 | - run: npm test
30 |
--------------------------------------------------------------------------------
/client/src/components/LogsTableRow/LogsTableRow.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import PropTypes from "prop-types";
3 | import styled from "@emotion/styled";
4 |
5 | const levelColors = {
6 | info: "--info-color",
7 | warning: "--warning-color",
8 | error: "--error-color",
9 | };
10 | const Level = styled.td`
11 | color: var(${(props) => levelColors[props.level]});
12 | `;
13 |
14 | const LogsTableRow = ({ log }) => {
15 | return (
16 |
17 | | {log.origin} |
18 | {log.createdAt} |
19 | {log.level}
20 | {log.message} |
21 |
22 | );
23 | };
24 |
25 | LogsTableRow.propTypes = {
26 | log: PropTypes.shape({
27 | id: PropTypes.string,
28 | origin: PropTypes.string,
29 | createdAt: PropTypes.string,
30 | message: PropTypes.string,
31 | level: PropTypes.oneOf(["info", "warning", "error"]),
32 | }),
33 | };
34 |
35 | export default LogsTableRow;
36 |
--------------------------------------------------------------------------------
/client/src/components/Header/Header.stories.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { Router } from "react-router-dom";
3 | import { createMemoryHistory } from "history";
4 | import PropTypes from "prop-types";
5 | import Header from "./Header";
6 |
7 | export default {
8 | title: "Header",
9 | component: Header,
10 | };
11 |
12 | const Template = ({ route, ...args }) => {
13 | const history = createMemoryHistory();
14 | history.push(route);
15 | return (
16 |
17 |
18 |
19 | );
20 | };
21 | Template.propTypes = {
22 | route: PropTypes.string,
23 | };
24 |
25 | export const Logs = Template.bind({});
26 | Logs.args = {
27 | route: "/",
28 | loggedIn: true,
29 | };
30 | export const Apps = Template.bind({ route: "/apps" });
31 | Apps.args = {
32 | route: "/apps",
33 | loggedIn: true,
34 | };
35 | export const LoggedOut = Template.bind({});
36 | LoggedOut.args = {
37 | route: "/login",
38 | loggedIn: false,
39 | };
40 |
--------------------------------------------------------------------------------
/client/src/pages/Logs/Logs.js:
--------------------------------------------------------------------------------
1 | import React, { useState } from "react";
2 | import LogsTable from "../../components/LogsTable/LogsTable";
3 | import LogsTableRow from "../../components/LogsTableRow/LogsTableRow";
4 | import { getLogs } from "../../api/logs";
5 | import useAsync from "../../hooks/useFetch";
6 | import LevelFilters from "../../components/LevelFilters";
7 | import { useDictMessages } from "../../i18n/context";
8 |
9 | const Logs = () => {
10 | const [filters, setFilters] = useState(["error", "warning", "info"]);
11 | const { data: logs, loading } = useAsync(getLogs, filters);
12 | const dictMessages = useDictMessages();
13 |
14 | return (
15 | <>
16 |
17 |
18 | {logs?.map((log) => (
19 |
20 | ))}
21 |
22 | {loading && {dictMessages.loading}
}
23 | >
24 | );
25 | };
26 |
27 | export default Logs;
28 |
--------------------------------------------------------------------------------
/client/src/i18n/context.js:
--------------------------------------------------------------------------------
1 | import React, { useContext, useEffect, useState } from "react";
2 | import PropTypes from "prop-types";
3 |
4 | export const I18nContext = React.createContext();
5 |
6 | export const I18nProvider = ({ children, lang = "en" }) => {
7 | const [dict, setDict] = useState({ locale: "", messages: {} });
8 |
9 | useEffect(() => {
10 | changeDict(lang);
11 | }, [lang]);
12 |
13 | const changeDict = async (lang) => {
14 | const dict = await import(`./${lang}.json`);
15 | setDict(dict);
16 | };
17 |
18 | return (
19 |
20 | {children}
21 |
22 | );
23 | };
24 |
25 | I18nProvider.propTypes = {
26 | children: PropTypes.node,
27 | lang: PropTypes.string.isRequired,
28 | };
29 |
30 | export const useI18n = () => {
31 | return useContext(I18nContext);
32 | };
33 |
34 | export const useDict = () => {
35 | return useI18n()[0];
36 | };
37 |
38 | export const useDictMessages = () => {
39 | return useDict().messages;
40 | };
41 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Leon Machens
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/server.js:
--------------------------------------------------------------------------------
1 | require("dotenv").config();
2 |
3 | const express = require("express");
4 | const path = require("path");
5 | const bodyParser = require("body-parser");
6 | const cookieParser = require("cookie-parser");
7 | const { connectDB } = require("./lib/db");
8 | const logsRouter = require("./lib/logsRouter");
9 | const authRouter = require("./lib/authRouter");
10 |
11 | const app = express();
12 | const port = process.env.PORT || 3001;
13 |
14 | app.use(bodyParser.json());
15 | app.use(cookieParser());
16 |
17 | // Serve any static files
18 | app.use(express.static(path.join(__dirname, "client/build")));
19 | app.use(
20 | "/storybook",
21 | express.static(path.join(__dirname, "client/storybook-static"))
22 | );
23 |
24 | app.use("/api/logs", logsRouter);
25 | app.use("/api", authRouter);
26 |
27 | // Handle React routing, return all requests to React app
28 | app.get("*", (req, res) => {
29 | res.sendFile(path.join(__dirname, "client/build", "index.html"));
30 | });
31 |
32 | const run = async () => {
33 | await connectDB();
34 | console.log("Database connected");
35 | app.listen(port, () => {
36 | console.log(`Server listening at http://localhost:${port}`);
37 | });
38 | };
39 |
40 | run();
41 |
--------------------------------------------------------------------------------
/client/src/assets/direction.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/client/src/assets/flow.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/client/src/components/LogsTable/LogsTable.stories.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | import LogsTable from "./LogsTable";
4 | import LogsTableRow from "../LogsTableRow";
5 |
6 | export default {
7 | title: "LogsTable",
8 | component: LogsTable,
9 | };
10 |
11 | const Template = (args) => ;
12 |
13 | export const Empty = Template.bind({});
14 | Empty.args = {
15 | children: (
16 |
17 | | No logs available |
18 |
19 | ),
20 | };
21 |
22 | const logs = [
23 | {
24 | id: "1",
25 | origin: "Trophy Hunter",
26 | createdAt: "2020-09-02T11:50:29.679Z",
27 | level: "error",
28 | message: "Server crashed",
29 | },
30 | {
31 | id: "2",
32 | origin: "Trophy Hunter",
33 | createdAt: "2020-09-03T11:50:29.679Z",
34 | level: "warning",
35 | message: "High Memory usage",
36 | },
37 | {
38 | id: "3",
39 | origin: "Server 2",
40 | createdAt: "2020-09-02T12:50:29.679Z",
41 | level: "info",
42 | message: "Server crashed",
43 | },
44 | {
45 | origin: "neuefische.de",
46 | createdAt: "2020-09-02T11:50:29.679Z",
47 | level: "error",
48 | message: "Server crashed",
49 | id: "SvG7lzQ",
50 | },
51 | ];
52 | export const Full = Template.bind({});
53 | Full.args = {
54 | children: logs.map((log) => ),
55 | };
56 |
--------------------------------------------------------------------------------
/client/src/assets/code-brackets.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/client/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "client",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@babel/core": "^7.11.5",
7 | "@emotion/core": "^10.0.35",
8 | "@emotion/styled": "^10.0.27",
9 | "@storybook/addon-actions": "^6.0.21",
10 | "@storybook/addon-essentials": "^6.0.21",
11 | "@storybook/addon-links": "^6.0.21",
12 | "@storybook/node-logger": "^6.0.21",
13 | "@storybook/preset-create-react-app": "^3.1.4",
14 | "@storybook/react": "^6.0.21",
15 | "@testing-library/jest-dom": "^4.2.4",
16 | "@testing-library/react": "^9.3.2",
17 | "@testing-library/user-event": "^7.1.2",
18 | "babel-loader": "^8.1.0",
19 | "react": "^16.13.1",
20 | "react-dom": "^16.13.1",
21 | "react-is": "^16.13.1",
22 | "react-router-dom": "^5.2.0",
23 | "react-scripts": "3.4.3"
24 | },
25 | "scripts": {
26 | "start": "react-scripts start",
27 | "build": "react-scripts build",
28 | "test": "react-scripts test",
29 | "eject": "react-scripts eject",
30 | "storybook": "start-storybook -p 6006 -s public",
31 | "build-storybook": "build-storybook -s public"
32 | },
33 | "browserslist": {
34 | "production": [
35 | ">0.2%",
36 | "not dead",
37 | "not op_mini all"
38 | ],
39 | "development": [
40 | "last 1 chrome version",
41 | "last 1 firefox version",
42 | "last 1 safari version"
43 | ]
44 | },
45 | "proxy": "http://localhost:3001"
46 | }
47 |
--------------------------------------------------------------------------------
/client/src/App.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import GlobalStyles from "./GlobalStyles";
3 | import {
4 | BrowserRouter as Router,
5 | Switch,
6 | Route,
7 | Redirect,
8 | } from "react-router-dom";
9 | import Apps from "./pages/Apps";
10 | import Logs from "./pages/Logs";
11 | import useCookie from "./hooks/useCookie";
12 | import Login from "./pages/Login";
13 | import styled from "@emotion/styled";
14 | import Header from "./components/Header";
15 | import { I18nProvider } from "./i18n/context";
16 |
17 | const AppHeader = styled(Header)`
18 | width: 80%;
19 | max-width: 1125px;
20 | margin: 3rem auto;
21 | `;
22 |
23 | const Main = styled.main`
24 | width: 80%;
25 | max-width: 1125px;
26 | margin-left: auto;
27 | margin-right: auto;
28 | `;
29 |
30 | function App() {
31 | const [authToken] = useCookie("authToken");
32 |
33 | return (
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | {!authToken && }
51 |
52 |
53 |
54 | );
55 | }
56 |
57 | export default App;
58 |
--------------------------------------------------------------------------------
/client/src/assets/comments.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/client/src/components/LevelFilters/LevelFilters.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import PropTypes from "prop-types";
3 | import ErrorButton from "../ErrorButton";
4 | import WarningButton from "../WarningButton";
5 | import InfoButton from "../InfoButton";
6 | import styled from "@emotion/styled";
7 |
8 | const Container = styled.div`
9 | button:not(:last-child) {
10 | margin-right: 1rem;
11 | }
12 | `;
13 |
14 | const LevelFilters = ({ filters = [], onChange }) => {
15 | const handleChange = (name) => () => {
16 | const oldFilters = [...filters];
17 | const index = oldFilters.indexOf(name);
18 | if (index > -1) {
19 | oldFilters.splice(index, 1);
20 | onChange(oldFilters);
21 | } else {
22 | onChange([...oldFilters, name]);
23 | }
24 | };
25 | return (
26 |
27 |
31 | Error
32 |
33 |
37 | Warning
38 |
39 |
43 | Info
44 |
45 |
46 | );
47 | };
48 |
49 | LevelFilters.propTypes = {
50 | filters: PropTypes.array,
51 | onChange: PropTypes.func,
52 | };
53 |
54 | export default LevelFilters;
55 |
--------------------------------------------------------------------------------
/lib/logsRouter.js:
--------------------------------------------------------------------------------
1 | const express = require("express");
2 | const jwt = require("jsonwebtoken");
3 | const { getCollection } = require("./db");
4 |
5 | const logsRouter = express.Router();
6 |
7 | logsRouter.post("/", async (request, response) => {
8 | try {
9 | const log = request.body;
10 |
11 | await getCollection("logs").insertOne(log);
12 | response.json("😁");
13 | } catch (error) {
14 | console.error(error);
15 | response.status(500).send("Internal server error");
16 | }
17 | });
18 |
19 | logsRouter.get("/", async (request, response) => {
20 | try {
21 | const { level } = request.query;
22 | const { authToken } = request.cookies;
23 |
24 | if (!authToken) {
25 | return response.status(401).end("Unauthorized");
26 | }
27 |
28 | const { email } = jwt.verify(authToken, process.env.JWT_SECRET);
29 | const account = await getCollection("accounts").findOne({ email });
30 | if (!account) {
31 | return response.status(401).end("Unauthorized");
32 | }
33 |
34 | let query = null;
35 | if (!level) {
36 | query = {};
37 | } else if (typeof level === "string") {
38 | query = {
39 | level: level,
40 | };
41 | } else if (Array.isArray(level)) {
42 | query = {
43 | level: { $in: level },
44 | };
45 | }
46 |
47 | const logs = await getCollection("logs").find(query).toArray();
48 | response.json(logs);
49 | } catch (error) {
50 | console.error(error);
51 | response.status(500).send("Internal server error");
52 | }
53 | });
54 |
55 | module.exports = logsRouter;
56 |
--------------------------------------------------------------------------------
/client/src/assets/repo.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/client/src/pages/Login/Login.js:
--------------------------------------------------------------------------------
1 | import styled from "@emotion/styled";
2 | import React, { useState } from "react";
3 | import { useHistory } from "react-router-dom";
4 | import { login } from "../../api/auth";
5 | import { useDictMessages } from "../../i18n/context";
6 |
7 | const Form = styled.form`
8 | max-width: 400px;
9 | margin: 0 auto;
10 |
11 | input {
12 | width: 100%;
13 | margin: 0.8rem 0;
14 | padding: 0.8rem 1rem;
15 | border: 1px solid #ccc;
16 | border-radius: 4px;
17 | }
18 |
19 | button {
20 | width: 100%;
21 | background-color: var(--active-color);
22 | color: var(--base-color);
23 | margin: 8px 0;
24 | padding: 0.8rem 1rem;
25 | border: none;
26 | border-radius: 4px;
27 | cursor: pointer;
28 |
29 | :disabled {
30 | cursor: default;
31 | background-color: var(--disabled-color);
32 | }
33 | }
34 | `;
35 |
36 | const Login = () => {
37 | const [email, setEmail] = useState("");
38 | const history = useHistory();
39 | const dictMessages = useDictMessages();
40 |
41 | const handleSubmit = async (event) => {
42 | event.preventDefault();
43 | await login({ email });
44 | history.push("/");
45 | };
46 |
47 | return (
48 |
58 | );
59 | };
60 |
61 | export default Login;
62 |
--------------------------------------------------------------------------------
/lib/authRouter.js:
--------------------------------------------------------------------------------
1 | const express = require("express");
2 | const jwt = require("jsonwebtoken");
3 |
4 | const { getCollection } = require("./db");
5 |
6 | const authRouter = express.Router();
7 |
8 | const ONE_MONTH_IN_SECONDS = 30 * 24 * 60 * 60;
9 | authRouter.post("/login", async (request, response) => {
10 | try {
11 | const { email } = request.body;
12 |
13 | const account = await getCollection("accounts").findOne({ email });
14 |
15 | if (!account) {
16 | return response.status(404).end("Account not found");
17 | }
18 | const authToken = jwt.sign({ email }, process.env.JWT_SECRET, {
19 | expiresIn: ONE_MONTH_IN_SECONDS,
20 | });
21 |
22 | response.setHeader(
23 | "Set-Cookie",
24 | `authToken=${authToken};path=/;Max-Age=${ONE_MONTH_IN_SECONDS}`
25 | );
26 | response.json(account);
27 | } catch (error) {
28 | console.error(error);
29 | response.status(500).send("Internal server error");
30 | }
31 | });
32 |
33 | authRouter.post("/register", async (request, response) => {
34 | try {
35 | const { email } = request.body;
36 |
37 | const existingAccount = await getCollection("accounts").findOne({ email });
38 |
39 | if (existingAccount) {
40 | return response.status(409).end("Account already exists");
41 | }
42 |
43 | const inserted = await getCollection("accounts").insertOne({ email });
44 | if (!inserted.result.ok) {
45 | return response.status(500).end("Can not register account");
46 | }
47 |
48 | const account = inserted.ops[0];
49 | response.json(account);
50 | } catch (error) {
51 | console.error(error);
52 | response.status(500).send("Internal server error");
53 | }
54 | });
55 | module.exports = authRouter;
56 |
--------------------------------------------------------------------------------
/client/src/components/Header/Header.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import styled from "@emotion/styled";
3 | import PropTypes from "prop-types";
4 | import logoSrc from "../../assets/logo.png";
5 | import { Link, useLocation } from "react-router-dom";
6 | import LanguageSelector from "../LanguageSelector";
7 |
8 | const FlexHeader = styled.header`
9 | display: flex;
10 | align-items: center;
11 |
12 | img {
13 | height: 3rem;
14 | margin-right: 1rem;
15 | }
16 |
17 | h1 {
18 | flex-grow: 1;
19 | font-size: 1.4rem;
20 | text-transform: uppercase;
21 | }
22 | ul {
23 | list-style: none;
24 | margin: 0;
25 |
26 | li {
27 | display: inline-block;
28 | margin-left: 1rem;
29 | }
30 | }
31 | `;
32 |
33 | const NavLink = styled(({ active, ...props }) => )`
34 | color: ${(props) => (props.active ? "var(--active-color)" : "inherit")};
35 | `;
36 |
37 | const Header = ({ loggedIn, ...props }) => {
38 | const location = useLocation();
39 |
40 | const navItems = loggedIn ? (
41 | <>
42 |
43 |
44 | Logs
45 |
46 |
47 |
48 |
49 | Apps
50 |
51 |
52 | >
53 | ) : (
54 |
55 |
56 | Login
57 |
58 |
59 | );
60 |
61 | return (
62 |
63 |
64 | Logs
65 |
66 |
69 |
70 | );
71 | };
72 |
73 | Header.propTypes = {
74 | loggedIn: PropTypes.bool,
75 | };
76 |
77 | export default Header;
78 |
--------------------------------------------------------------------------------
/client/src/GlobalStyles.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { Global, css } from "@emotion/core";
3 |
4 | const GlobalStyles = () => (
5 |
69 | );
70 |
71 | export default GlobalStyles;
72 |
--------------------------------------------------------------------------------
/client/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | CRA-With-API
28 |
29 |
30 |
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/client/src/assets/plugin.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | lerna-debug.log*
8 |
9 | # Diagnostic reports (https://nodejs.org/api/report.html)
10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11 |
12 | # Runtime data
13 | pids
14 | *.pid
15 | *.seed
16 | *.pid.lock
17 |
18 | # Directory for instrumented libs generated by jscoverage/JSCover
19 | lib-cov
20 |
21 | # Coverage directory used by tools like istanbul
22 | coverage
23 | *.lcov
24 |
25 | # nyc test coverage
26 | .nyc_output
27 |
28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29 | .grunt
30 |
31 | # Bower dependency directory (https://bower.io/)
32 | bower_components
33 |
34 | # node-waf configuration
35 | .lock-wscript
36 |
37 | # Compiled binary addons (https://nodejs.org/api/addons.html)
38 | build/Release
39 |
40 | # Dependency directories
41 | node_modules/
42 | jspm_packages/
43 |
44 | # TypeScript v1 declaration files
45 | typings/
46 |
47 | # TypeScript cache
48 | *.tsbuildinfo
49 |
50 | # Optional npm cache directory
51 | .npm
52 |
53 | # Optional eslint cache
54 | .eslintcache
55 |
56 | # Microbundle cache
57 | .rpt2_cache/
58 | .rts2_cache_cjs/
59 | .rts2_cache_es/
60 | .rts2_cache_umd/
61 |
62 | # Optional REPL history
63 | .node_repl_history
64 |
65 | # Output of 'npm pack'
66 | *.tgz
67 |
68 | # Yarn Integrity file
69 | .yarn-integrity
70 |
71 | # dotenv environment variables file
72 | .env
73 | .env.test
74 |
75 | # parcel-bundler cache (https://parceljs.org/)
76 | .cache
77 |
78 | # Next.js build output
79 | .next
80 |
81 | # Nuxt.js build / generate output
82 | .nuxt
83 | dist
84 |
85 | # Gatsby files
86 | .cache/
87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js
88 | # https://nextjs.org/blog/next-9-1#public-directory-support
89 | # public
90 |
91 | # vuepress build output
92 | .vuepress/dist
93 |
94 | # Serverless directories
95 | .serverless/
96 |
97 | # FuseBox cache
98 | .fusebox/
99 |
100 | # DynamoDB Local files
101 | .dynamodb/
102 |
103 | # TernJS port file
104 | .tern-port
105 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "cra-with-api",
3 | "private": true,
4 | "version": "1.0.0",
5 | "description": "Boilerplate for Create-React-App with an Express.js API",
6 | "main": "server.js",
7 | "scripts": {
8 | "postinstall": "cd client && npm install",
9 | "build": "cd client && npm run build && npm run build-storybook",
10 | "test": "npm run lint && cd client && npm test",
11 | "lint": "eslint . --ext .js",
12 | "prettify": "prettier --write .",
13 | "dev": "concurrently \"npm run server\" \"npm run client\"",
14 | "client": "cd client && npm start",
15 | "server": "nodemon server.js",
16 | "storybook": "cd client && npm run storybook",
17 | "start": "node server.js"
18 | },
19 | "repository": {
20 | "type": "git",
21 | "url": "git+https://github.com/lmachens/cra-with-api.git"
22 | },
23 | "keywords": [],
24 | "author": "Leon Machens",
25 | "license": "MIT",
26 | "bugs": {
27 | "url": "https://github.com/lmachens/cra-with-api/issues"
28 | },
29 | "homepage": "https://github.com/lmachens/cra-with-api#readme",
30 | "dependencies": {
31 | "body-parser": "^1.19.0",
32 | "cookie-parser": "^1.4.5",
33 | "dotenv": "^8.2.0",
34 | "express": "^4.17.1",
35 | "js-cookie": "^2.2.1",
36 | "jsonwebtoken": "^8.5.1",
37 | "mongodb": "^3.6.1"
38 | },
39 | "devDependencies": {
40 | "@typescript-eslint/eslint-plugin": "^4.0.1",
41 | "@typescript-eslint/parser": "^4.0.1",
42 | "babel-eslint": "^10.1.0",
43 | "concurrently": "^5.3.0",
44 | "eslint": "^6.6.0",
45 | "eslint-config-prettier": "^6.11.0",
46 | "eslint-config-react-app": "^5.2.1",
47 | "eslint-plugin-flowtype": "^5.2.0",
48 | "eslint-plugin-import": "^2.22.0",
49 | "eslint-plugin-jsx-a11y": "^6.3.1",
50 | "eslint-plugin-react": "^7.20.6",
51 | "eslint-plugin-react-hooks": "^4.1.0",
52 | "husky": "^4.2.5",
53 | "lint-staged": "^10.2.13",
54 | "nodemon": "^2.0.4",
55 | "prettier": "2.1.1",
56 | "typescript": "^4.0.2"
57 | },
58 | "husky": {
59 | "hooks": {
60 | "pre-commit": "lint-staged"
61 | }
62 | },
63 | "lint-staged": {
64 | "*.js": "eslint --cache --fix",
65 | "*.{js,css,md}": "prettier --write"
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/client/src/assets/stackalt.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/client/README.md:
--------------------------------------------------------------------------------
1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2 |
3 | ## Available Scripts
4 |
5 | In the project directory, you can run:
6 |
7 | ### `npm start`
8 |
9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11 |
12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console.
14 |
15 | ### `npm test`
16 |
17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19 |
20 | ### `npm run build`
21 |
22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance.
24 |
25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed!
27 |
28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29 |
30 | ### `npm run eject`
31 |
32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33 |
34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
35 |
36 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
37 |
38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
39 |
40 | ## Learn More
41 |
42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43 |
44 | To learn React, check out the [React documentation](https://reactjs.org/).
45 |
46 | ### Code Splitting
47 |
48 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
49 |
50 | ### Analyzing the Bundle Size
51 |
52 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
53 |
54 | ### Making a Progressive Web App
55 |
56 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
57 |
58 | ### Advanced Configuration
59 |
60 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
61 |
62 | ### Deployment
63 |
64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
65 |
66 | ### `npm run build` fails to minify
67 |
68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
69 |
--------------------------------------------------------------------------------
/client/src/serviceWorker.js:
--------------------------------------------------------------------------------
1 | // This optional code is used to register a service worker.
2 | // register() is not called by default.
3 |
4 | // This lets the app load faster on subsequent visits in production, and gives
5 | // it offline capabilities. However, it also means that developers (and users)
6 | // will only see deployed updates on subsequent visits to a page, after all the
7 | // existing tabs open on the page have been closed, since previously cached
8 | // resources are updated in the background.
9 |
10 | // To learn more about the benefits of this model and instructions on how to
11 | // opt-in, read https://bit.ly/CRA-PWA
12 |
13 | const isLocalhost = Boolean(
14 | window.location.hostname === "localhost" ||
15 | // [::1] is the IPv6 localhost address.
16 | window.location.hostname === "[::1]" ||
17 | // 127.0.0.0/8 are considered localhost for IPv4.
18 | window.location.hostname.match(
19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
20 | )
21 | );
22 |
23 | export function register(config) {
24 | if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) {
25 | // The URL constructor is available in all browsers that support SW.
26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
27 | if (publicUrl.origin !== window.location.origin) {
28 | // Our service worker won't work if PUBLIC_URL is on a different origin
29 | // from what our page is served on. This might happen if a CDN is used to
30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374
31 | return;
32 | }
33 |
34 | window.addEventListener("load", () => {
35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
36 |
37 | if (isLocalhost) {
38 | // This is running on localhost. Let's check if a service worker still exists or not.
39 | checkValidServiceWorker(swUrl, config);
40 |
41 | // Add some additional logging to localhost, pointing developers to the
42 | // service worker/PWA documentation.
43 | navigator.serviceWorker.ready.then(() => {
44 | console.log(
45 | "This web app is being served cache-first by a service " +
46 | "worker. To learn more, visit https://bit.ly/CRA-PWA"
47 | );
48 | });
49 | } else {
50 | // Is not localhost. Just register service worker
51 | registerValidSW(swUrl, config);
52 | }
53 | });
54 | }
55 | }
56 |
57 | function registerValidSW(swUrl, config) {
58 | navigator.serviceWorker
59 | .register(swUrl)
60 | .then((registration) => {
61 | registration.onupdatefound = () => {
62 | const installingWorker = registration.installing;
63 | if (installingWorker == null) {
64 | return;
65 | }
66 | installingWorker.onstatechange = () => {
67 | if (installingWorker.state === "installed") {
68 | if (navigator.serviceWorker.controller) {
69 | // At this point, the updated precached content has been fetched,
70 | // but the previous service worker will still serve the older
71 | // content until all client tabs are closed.
72 | console.log(
73 | "New content is available and will be used when all " +
74 | "tabs for this page are closed. See https://bit.ly/CRA-PWA."
75 | );
76 |
77 | // Execute callback
78 | if (config && config.onUpdate) {
79 | config.onUpdate(registration);
80 | }
81 | } else {
82 | // At this point, everything has been precached.
83 | // It's the perfect time to display a
84 | // "Content is cached for offline use." message.
85 | console.log("Content is cached for offline use.");
86 |
87 | // Execute callback
88 | if (config && config.onSuccess) {
89 | config.onSuccess(registration);
90 | }
91 | }
92 | }
93 | };
94 | };
95 | })
96 | .catch((error) => {
97 | console.error("Error during service worker registration:", error);
98 | });
99 | }
100 |
101 | function checkValidServiceWorker(swUrl, config) {
102 | // Check if the service worker can be found. If it can't reload the page.
103 | fetch(swUrl, {
104 | headers: { "Service-Worker": "script" },
105 | })
106 | .then((response) => {
107 | // Ensure service worker exists, and that we really are getting a JS file.
108 | const contentType = response.headers.get("content-type");
109 | if (
110 | response.status === 404 ||
111 | (contentType != null && contentType.indexOf("javascript") === -1)
112 | ) {
113 | // No service worker found. Probably a different app. Reload the page.
114 | navigator.serviceWorker.ready.then((registration) => {
115 | registration.unregister().then(() => {
116 | window.location.reload();
117 | });
118 | });
119 | } else {
120 | // Service worker found. Proceed as normal.
121 | registerValidSW(swUrl, config);
122 | }
123 | })
124 | .catch(() => {
125 | console.log(
126 | "No internet connection found. App is running in offline mode."
127 | );
128 | });
129 | }
130 |
131 | export function unregister() {
132 | if ("serviceWorker" in navigator) {
133 | navigator.serviceWorker.ready
134 | .then((registration) => {
135 | registration.unregister();
136 | })
137 | .catch((error) => {
138 | console.error(error.message);
139 | });
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/client/src/assets/colors.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------