├── .babelrc ├── .dockerignore ├── .gitignore ├── Dockerfile ├── Jenkinsfile ├── README.md ├── chart └── base │ ├── .helmignore │ ├── Chart.yaml │ ├── templates │ ├── NOTES.txt │ ├── _helpers.tpl │ ├── deployment.yaml │ ├── ingress.yaml │ ├── route.yaml │ └── service.yaml │ └── values.yaml ├── client ├── README.md ├── config │ ├── env.js │ ├── jest │ │ ├── cssTransform.js │ │ └── fileTransform.js │ ├── paths.js │ ├── webpack.config.dev.js │ ├── webpack.config.prod.js │ └── webpackDevServer.config.js ├── package-lock.json ├── package.json ├── public │ ├── favicon.ico │ ├── index.html │ └── manifest.json ├── scripts │ ├── build.js │ ├── start.js │ └── test.js └── src │ ├── App.jsx │ ├── App.scss │ ├── App.test.jsx │ ├── components │ ├── UIShell.jsx │ └── UIShellBody.jsx │ ├── index.css │ ├── index.html │ ├── index.js │ ├── logo.svg │ ├── pattern-components │ ├── CreateReadUpdateDelete.jsx │ ├── DisplayForm.jsx │ ├── Header.jsx │ ├── LinkedList.jsx │ ├── ListToList.jsx │ ├── MasterDetail.jsx │ ├── SearchForm.jsx │ ├── SearchList.jsx │ ├── SimpleList.jsx │ ├── TableList.jsx │ ├── UpdateForm.jsx │ ├── ValidatingForm.jsx │ ├── ValidatingFormWizard1.jsx │ ├── ValidatingFormWizard2.jsx │ └── patterns.scss │ ├── serviceWorker.js │ └── util │ ├── timer.js │ └── timer.test.js ├── licenses └── LICENSE.txt ├── package-lock.json ├── package.json ├── pipeline.yaml ├── public ├── 404.html ├── 500.html └── index.html ├── scripts ├── build.sh ├── publish.sh ├── pull.sh └── test.sh ├── server ├── config │ ├── local.json │ └── mappings.json ├── routers │ ├── api.js │ ├── health.js │ ├── index.js │ └── public.js ├── server.js └── services │ ├── index.js │ └── service-manager.js ├── sonar-project.properties ├── test ├── sonarqube-scan.js ├── test-demo.js └── test-server.js └── tsconfig.json /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["env"] 3 | } 4 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .idea/**/* 3 | *.iml 4 | node_modules 5 | node_modules/**/* 6 | client/node_modules 7 | client/node_modules/**/* 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | node_modules 4 | node_modules_linux 5 | coverage 6 | server/localdev-config.json 7 | server/localdev-config.json 8 | vcap-local.js 9 | credentials.json 10 | localdev-config.json 11 | index.yaml 12 | 13 | # dependencies 14 | /node_modules 15 | /client/node_modules 16 | /.pnp 17 | .pnp.js 18 | 19 | # testing 20 | /coverage 21 | 22 | # production 23 | /build 24 | /client/build 25 | 26 | # misc 27 | .DS_Store 28 | .env.local 29 | .env.development.local 30 | .env.test.local 31 | .env.production.local 32 | 33 | npm-debug.log* 34 | yarn-debug.log* 35 | yarn-error.log* 36 | 37 | .tmp 38 | 39 | .nyc_output 40 | 41 | pipeline-build-config.json 42 | .idea/ 43 | *.iml 44 | .scannerwork/ 45 | env-config 46 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM registry.redhat.io/rhel9/nodejs-16:1-44 AS builder 2 | 3 | WORKDIR /opt/app-root/src 4 | 5 | RUN mkdir client 6 | COPY --chown=default:root client client 7 | COPY client/package*.json client/ 8 | COPY package*.json ./ 9 | RUN npm ci 10 | 11 | WORKDIR /opt/app-root/src/client 12 | 13 | RUN npm ci && npm run build 14 | 15 | FROM registry.redhat.io/rhel9/nodejs-16:1-44 16 | 17 | WORKDIR /opt/app-root/src 18 | COPY --from=builder /opt/app-root/src/client/build client/build 19 | COPY public public 20 | COPY server server 21 | COPY client/package*.json client/ 22 | COPY package.json . 23 | RUN npm install --production 24 | 25 | ENV NODE_ENV=production 26 | ENV HOST=0.0.0.0 PORT=3000 27 | 28 | EXPOSE 3000/tcp 29 | 30 | 31 | 32 | ## Uncomment the below line to update image security content if any 33 | # USER root 34 | # RUN dnf -y update-minimal --security --sec-severity=Important --sec-severity=Critical && dnf clean all 35 | 36 | COPY ./licenses /licenses 37 | 38 | USER default 39 | 40 | LABEL name="ibm/template-node-react" \ 41 | vendor="IBM" \ 42 | version="1" \ 43 | release="77.1618436962" \ 44 | summary="This is an example of a container image." \ 45 | description="This container image will deploy a React Node App" 46 | 47 | CMD ["npm", "start"] 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | IBM Cloud 4 | 5 |

6 | 7 |

8 | 9 | IBM Cloud 10 | 11 | platform 12 | Apache 2 13 |

14 | 15 | # React UI Patterns with Node.js 16 | 17 | React is a popular framework for creating user interfaces in modular components. In this sample application, you will create a web application using Express and React to serve web pages in Node.js, complete with standard best practices, including a health check and application metric monitoring. 18 | 19 | This code pattern contains 12 popular UI patterns that make it very easy to construct a dashboard application. 20 | 21 | This app contains an opinionated set of components for modern web development, including: 22 | 23 | * [React](https://facebook.github.io/react/) 24 | * [Webpack](https://webpack.github.io/) 25 | * [Sass](http://sass-lang.com/) 26 | * [gulp](http://gulpjs.com/) 27 | * [Carbon](https://www.carbondesignsystem.com/) 28 | 29 | ### Deploying 30 | 31 | After you have created a new git repo from this git template, remember to rename the project. 32 | Edit `package.json` and change the default name to the name you used to create the template. 33 | 34 | Make sure you are logged into the IBM Cloud using the IBM Cloud CLI and have access 35 | to you development cluster. If you are using OpenShift make sure you have logged into OpenShift CLI on the command line. 36 | 37 | ```$bash 38 | npm install -g @ibmgaragecloud/cloud-native-toolkit-cli 39 | ``` 40 | 41 | Use the IBM Garage for Cloud CLI to register the GIT Repo with Tekton or Jenkins 42 | 43 | ```$bash 44 | oc sync --dev 45 | oc pipeline 46 | ``` 47 | 48 | Ensure you have the Cloud-Native Toolkit installed in your cluster to make this method of pipeline registry quick and easy [Cloud-Native Toolkit](https://cloudnativetoolkit.dev/) 49 | 50 | #### Native Application Development 51 | 52 | Install the latest [Node.js](https://nodejs.org/en/download/) 6+ LTS version. 53 | 54 | Once the Node toolchain has been installed, you can download the project dependencies with: 55 | 56 | ```bash 57 | npm install 58 | cd client; npm install; cd .. 59 | npm run build 60 | npm run start 61 | ``` 62 | 63 | Modern web applications require a compilation step to prepare your ES2015 JavaScript or Sass stylesheets into compressed Javascript ready for a browser. Webpack is used for bundling your JavaScript sources and styles into a `bundle.js` file that your `index.html` file can import. 64 | 65 | ***Webpack*** 66 | 67 | For development mode, use `webpack -d` to leave the sources uncompress and with the symbols intact. 68 | 69 | For production mode, use `webpack -p` to compress and obfuscate your sources for development usage. 70 | 71 | ***Gulp*** 72 | 73 | Gulp is a task runner for JavaScript. You can run the above Webpack commands in by running: 74 | ```bash 75 | gulp 76 | ``` 77 | 78 | To run your application locally: 79 | ```bash 80 | npm run start 81 | ``` 82 | 83 | Your application will be running at `http://localhost:3000`. You can access the `/health` and `/appmetrics-dash` endpoints at the host. 84 | 85 | 111 | 112 | ##### Session Store 113 | 114 | You may see this warning when running `ibmcloud dev run`: 115 | ``` 116 | Warning: connect.session() MemoryStore is not 117 | designed for a production environment, as it will leak 118 | memory, and will not scale past a single process. 119 | ``` 120 | 121 | When deploying to production, it is best practice to configure sessions to be stored in an external persistence service. 122 | 123 | ## Next Steps 124 | 125 | * Learn more about augmenting your Node.js applications on IBM Cloud with the [Node Programming Guide](https://cloud.ibm.com/docs/node?topic=nodejs-getting-started). 126 | * Explore other [sample applications](https://cloud.ibm.com/developer/appservice/starter-kits) on IBM Cloud. 127 | 128 | ## License 129 | 130 | This sample application is licensed under the Apache License, Version 2. Separate third-party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the [Developer Certificate of Origin, Version 1.1](https://developercertificate.org/) and the [Apache License, Version 2](https://www.apache.org/licenses/LICENSE-2.0.txt). 131 | 132 | [Apache License FAQ](https://www.apache.org/foundation/license-faq.html#WhatDoesItMEAN) 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /chart/base/.helmignore: -------------------------------------------------------------------------------- 1 | # Patterns to ignore when building packages. 2 | # This supports shell glob matching, relative path matching, and 3 | # negation (prefixed with !). Only one pattern per line. 4 | .DS_Store 5 | # Common VCS dirs 6 | .git/ 7 | .gitignore 8 | .bzr/ 9 | .bzrignore 10 | .hg/ 11 | .hgignore 12 | .svn/ 13 | # Common backup files 14 | *.swp 15 | *.bak 16 | *.tmp 17 | *~ 18 | # Various IDEs 19 | .project 20 | .idea/ 21 | *.tmproj 22 | .vscode/ 23 | -------------------------------------------------------------------------------- /chart/base/Chart.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | appVersion: "1.0" 3 | description: A Helm chart for Kubernetes 4 | name: base 5 | version: 1.1.3 6 | branch: stable 7 | -------------------------------------------------------------------------------- /chart/base/templates/NOTES.txt: -------------------------------------------------------------------------------- 1 | 1. Get the application URL by running these commands: 2 | {{- if .Values.ingress.enabled }} 3 | {{ include "starter-kit.url" . }} 4 | {{- else if contains "NodePort" .Values.service.type }} 5 | export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "starter-kit.fullname" . }}) 6 | export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") 7 | echo http://$NODE_IP:$NODE_PORT 8 | {{- else if contains "LoadBalancer" .Values.service.type }} 9 | NOTE: It may take a few minutes for the LoadBalancer IP to be available. 10 | You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "starter-kit.fullname" . }}' 11 | export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "starter-kit.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') 12 | echo http://$SERVICE_IP:{{ .Values.service.port }} 13 | {{- else if contains "ClusterIP" .Values.service.type }} 14 | export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "starter-kit.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") 15 | echo "Visit http://127.0.0.1:8080 to use your application" 16 | kubectl port-forward $POD_NAME 8080:80 17 | {{- end }} 18 | -------------------------------------------------------------------------------- /chart/base/templates/_helpers.tpl: -------------------------------------------------------------------------------- 1 | {{/* vim: set filetype=mustache: */}} 2 | {{/* 3 | Expand the name of the chart. 4 | */}} 5 | {{- define "starter-kit.name" -}} 6 | {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} 7 | {{- end -}} 8 | 9 | {{/* 10 | Create a default fully qualified app name. 11 | We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). 12 | If release name contains chart name it will be used as a full name. 13 | */}} 14 | {{- define "starter-kit.fullname" -}} 15 | {{- if .Values.fullnameOverride -}} 16 | {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} 17 | {{- else -}} 18 | {{- $name := include "starter-kit.name" . -}} 19 | {{- if contains $name .Release.Name -}} 20 | {{- .Release.Name | trunc 63 | trimSuffix "-" -}} 21 | {{- else -}} 22 | {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} 23 | {{- end -}} 24 | {{- end -}} 25 | {{- end -}} 26 | 27 | {{/* 28 | Create chart name and version as used by the chart label. 29 | */}} 30 | {{- define "starter-kit.chart" -}} 31 | {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} 32 | {{- end -}} 33 | 34 | {{- define "starter-kit.host" -}} 35 | {{- $chartName := include "starter-kit.name" . -}} 36 | {{- $host := default $chartName .Values.ingress.host -}} 37 | {{- $subdomain := default .Values.ingress.subdomain .Values.global.ingressSubdomain -}} 38 | {{- if .Values.ingress.namespaceInHost -}} 39 | {{- printf "%s-%s.%s" $host .Release.Namespace $subdomain -}} 40 | {{- else -}} 41 | {{- printf "%s.%s" $host $subdomain -}} 42 | {{- end -}} 43 | {{- end -}} 44 | 45 | {{- define "starter-kit.url" -}} 46 | {{- $secretName := include "starter-kit.tlsSecretName" . -}} 47 | {{- $host := include "starter-kit.host" . -}} 48 | {{- if $secretName -}} 49 | {{- printf "https://%s" $host -}} 50 | {{- else -}} 51 | {{- printf "http://%s" $host -}} 52 | {{- end -}} 53 | {{- end -}} 54 | 55 | {{- define "starter-kit.protocols" -}} 56 | {{- $secretName := include "starter-kit.tlsSecretName" . -}} 57 | {{- if $secretName -}} 58 | {{- printf "%s,%s" "http" "https" -}} 59 | {{- else -}} 60 | {{- printf "%s" "http" -}} 61 | {{- end -}} 62 | {{- end -}} 63 | 64 | {{- define "starter-kit.tlsSecretName" -}} 65 | {{- $secretName := default .Values.ingress.tlsSecretName .Values.global.tlsSecretName -}} 66 | {{- if $secretName }} 67 | {{- printf "%s" $secretName -}} 68 | {{- else -}} 69 | {{- printf "" -}} 70 | {{- end -}} 71 | {{- end -}} 72 | -------------------------------------------------------------------------------- /chart/base/templates/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: {{ include "starter-kit.fullname" . }} 5 | annotations: 6 | {{- if and .Values.vcsInfo.repoUrl .Values.vcsInfo.branch }} 7 | app.openshift.io/vcs-ref: {{ .Values.vcsInfo.branch }} 8 | app.openshift.io/vcs-uri: {{ .Values.vcsInfo.repoUrl }} 9 | {{- end }} 10 | {{- if .Values.connectsTo }} 11 | app.openshift.io/connects-to: {{ .Values.connectsTo }} 12 | {{- end }} 13 | labels: 14 | app.kubernetes.io/name: {{ include "starter-kit.name" . }} 15 | helm.sh/chart: {{ include "starter-kit.chart" . }} 16 | app.kubernetes.io/instance: {{ .Release.Name }} 17 | app: {{ .Release.Name }} 18 | {{- if .Values.partOf }} 19 | app.kubernetes.io/part-of: {{ .Values.partOf }} 20 | {{- end}} 21 | {{- if .Values.runtime }} 22 | app.openshift.io/runtime: {{ .Values.runtime }} 23 | {{- end}} 24 | spec: 25 | replicas: {{ .Values.replicaCount }} 26 | selector: 27 | matchLabels: 28 | app.kubernetes.io/name: {{ include "starter-kit.name" . }} 29 | app.kubernetes.io/instance: {{ .Release.Name }} 30 | template: 31 | metadata: 32 | labels: 33 | app.kubernetes.io/name: {{ include "starter-kit.name" . }} 34 | app.kubernetes.io/instance: {{ .Release.Name }} 35 | spec: 36 | {{- if .Values.image.secretName }} 37 | imagePullSecrets: 38 | - name: {{ .Values.image.secretName }} 39 | {{- end }} 40 | containers: 41 | - name: {{ .Chart.Name }} 42 | image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" 43 | imagePullPolicy: {{ .Values.image.pullPolicy }} 44 | 45 | ports: 46 | - name: http 47 | containerPort: {{ .Values.image.port }} 48 | protocol: TCP 49 | livenessProbe: 50 | httpGet: 51 | path: / 52 | port: http 53 | readinessProbe: 54 | httpGet: 55 | path: / 56 | port: http 57 | env: 58 | - name: INGRESS_HOST 59 | value: "" 60 | - name: PROTOCOLS 61 | value: "" 62 | - name: LOG_LEVEL 63 | value: {{ .Values.logLevel | quote }} 64 | resources: 65 | {{- toYaml .Values.resources | nindent 12 }} 66 | {{- with .Values.nodeSelector }} 67 | nodeSelector: 68 | {{- toYaml . | nindent 8 }} 69 | {{- end }} 70 | {{- with .Values.affinity }} 71 | affinity: 72 | {{- toYaml . | nindent 8 }} 73 | {{- end }} 74 | {{- with .Values.tolerations }} 75 | tolerations: 76 | {{- toYaml . | nindent 8 }} 77 | {{- end }} 78 | -------------------------------------------------------------------------------- /chart/base/templates/ingress.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.ingress.enabled -}} 2 | {{- $fullName := include "starter-kit.fullname" . -}} 3 | {{- $namespace := .Release.Namespace -}} 4 | {{- $requestType := .Values.ingress.appid.requestType -}} 5 | apiVersion: networking.k8s.io/v1beta1 6 | kind: Ingress 7 | metadata: 8 | name: {{ $fullName }} 9 | labels: 10 | app.kubernetes.io/name: {{ include "starter-kit.name" . }} 11 | helm.sh/chart: {{ include "starter-kit.chart" . }} 12 | app.kubernetes.io/instance: {{ .Release.Name }} 13 | app: {{ .Release.Name }} 14 | {{- if .Values.ingress.appid.enabled }} 15 | annotations: 16 | ingress.bluemix.net/appid-auth: {{ printf "bindSecret=%s namespace=%s requestType=%s serviceName=%s" (required "AppId binding is required to enable auth on the ingress" .Values.appidBinding) $namespace $requestType $fullName }} 17 | {{- end}} 18 | spec: 19 | {{- if include "starter-kit.tlsSecretName" . }} 20 | tls: 21 | - hosts: 22 | - {{ include "starter-kit.host" . }} 23 | secretName: {{ include "starter-kit.tlsSecretName" . }} 24 | {{- end }} 25 | rules: 26 | - host: {{ include "starter-kit.host" . }} 27 | http: 28 | paths: 29 | - path: {{ .path }} 30 | backend: 31 | serviceName: {{ $fullName }} 32 | servicePort: http 33 | {{- end }} 34 | -------------------------------------------------------------------------------- /chart/base/templates/route.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.route.enabled -}} 2 | {{- $fullName := include "starter-kit.fullname" . -}} 3 | kind: Route 4 | apiVersion: route.openshift.io/v1 5 | metadata: 6 | name: {{ $fullName }} 7 | annotations: 8 | argocd.argoproj.io/sync-options: Validate=false 9 | spec: 10 | to: 11 | kind: Service 12 | name: {{ $fullName }} 13 | weight: 100 14 | tls: 15 | termination: edge 16 | wildcardPolicy: None 17 | {{- end }} -------------------------------------------------------------------------------- /chart/base/templates/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | name: {{ include "starter-kit.fullname" . }} 5 | labels: 6 | app.kubernetes.io/name: {{ include "starter-kit.name" . }} 7 | helm.sh/chart: {{ include "starter-kit.chart" . }} 8 | app.kubernetes.io/instance: {{ .Release.Name }} 9 | app: {{ .Release.Name }} 10 | spec: 11 | type: {{ .Values.service.type }} 12 | ports: 13 | - port: {{ .Values.service.port }} 14 | targetPort: {{ .Values.image.port }} 15 | protocol: TCP 16 | name: http 17 | selector: 18 | app.kubernetes.io/name: {{ include "starter-kit.name" . }} 19 | app.kubernetes.io/instance: {{ .Release.Name }} 20 | -------------------------------------------------------------------------------- /chart/base/values.yaml: -------------------------------------------------------------------------------- 1 | # Default values for template-node-typescript. 2 | # This is a YAML-formatted file. 3 | # Declare variables to be passed into your templates. 4 | global: {} 5 | 6 | replicaCount: 1 7 | logLevel: "debug" 8 | 9 | image: 10 | repository: replace 11 | tag: replace 12 | pullPolicy: IfNotPresent 13 | port: 3000 14 | 15 | nameOverride: "" 16 | fullnameOverride: "" 17 | 18 | service: 19 | type: ClusterIP 20 | port: 80 21 | 22 | route: 23 | enabled: false 24 | 25 | ingress: 26 | enabled: true 27 | appid: 28 | enabled: false 29 | # web or app - https://cloud.ibm.com/docs/services/appid?topic=appid-kube-auth 30 | requestType: web 31 | 32 | # host: hello 33 | namespaceInHost: true 34 | subdomain: containers.appdomain.cloud 35 | path: "/" 36 | 37 | # tlsSecretName: "" 38 | 39 | vcsInfo: 40 | repoUrl: "" 41 | branch: "" 42 | 43 | partOf: "" 44 | 45 | connectsTo: "" 46 | 47 | runtime: js 48 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /client/config/env.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | const path = require('path'); 5 | const paths = require('./paths'); 6 | 7 | // Make sure that including paths.js after env.js will read .env variables. 8 | delete require.cache[require.resolve('./paths')]; 9 | 10 | const NODE_ENV = process.env.NODE_ENV; 11 | if (!NODE_ENV) { 12 | throw new Error( 13 | 'The NODE_ENV environment variable is required but was not specified.' 14 | ); 15 | } 16 | 17 | // https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use 18 | var dotenvFiles = [ 19 | `${paths.dotenv}.${NODE_ENV}.local`, 20 | `${paths.dotenv}.${NODE_ENV}`, 21 | // Don't include `.env.local` for `test` environment 22 | // since normally you expect tests to produce the same 23 | // results for everyone 24 | NODE_ENV !== 'test' && `${paths.dotenv}.local`, 25 | paths.dotenv, 26 | ].filter(Boolean); 27 | 28 | // Load environment variables from .env* files. Suppress warnings using silent 29 | // if this file is missing. dotenv will never modify any environment variables 30 | // that have already been set. Variable expansion is supported in .env files. 31 | // https://github.com/motdotla/dotenv 32 | // https://github.com/motdotla/dotenv-expand 33 | dotenvFiles.forEach(dotenvFile => { 34 | if (fs.existsSync(dotenvFile)) { 35 | require('dotenv-expand')( 36 | require('dotenv').config({ 37 | path: dotenvFile, 38 | }) 39 | ); 40 | } 41 | }); 42 | 43 | // We support resolving modules according to `NODE_PATH`. 44 | // This lets you use absolute paths in imports inside large monorepos: 45 | // https://github.com/facebook/create-react-app/issues/253. 46 | // It works similar to `NODE_PATH` in Node itself: 47 | // https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders 48 | // Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored. 49 | // Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims. 50 | // https://github.com/facebook/create-react-app/issues/1023#issuecomment-265344421 51 | // We also resolve them to make sure all tools using them work consistently. 52 | const appDirectory = fs.realpathSync(process.cwd()); 53 | process.env.NODE_PATH = (process.env.NODE_PATH || '') 54 | .split(path.delimiter) 55 | .filter(folder => folder && !path.isAbsolute(folder)) 56 | .map(folder => path.resolve(appDirectory, folder)) 57 | .join(path.delimiter); 58 | 59 | // Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be 60 | // injected into the application via DefinePlugin in Webpack configuration. 61 | const REACT_APP = /^REACT_APP_/i; 62 | 63 | function getClientEnvironment(publicUrl) { 64 | const raw = Object.keys(process.env) 65 | .filter(key => REACT_APP.test(key)) 66 | .reduce( 67 | (env, key) => { 68 | env[key] = process.env[key]; 69 | return env; 70 | }, 71 | { 72 | // Useful for determining whether we’re running in production mode. 73 | // Most importantly, it switches React into the correct mode. 74 | NODE_ENV: process.env.NODE_ENV || 'development', 75 | // Useful for resolving the correct path to static assets in `public`. 76 | // For example, . 77 | // This should only be used as an escape hatch. Normally you would put 78 | // images into the `src` and `import` them in code to get their paths. 79 | PUBLIC_URL: publicUrl, 80 | } 81 | ); 82 | // Stringify all values so we can feed into Webpack DefinePlugin 83 | const stringified = { 84 | 'process.env': Object.keys(raw).reduce((env, key) => { 85 | env[key] = JSON.stringify(raw[key]); 86 | return env; 87 | }, {}), 88 | }; 89 | 90 | return { raw, stringified }; 91 | } 92 | 93 | module.exports = getClientEnvironment; 94 | -------------------------------------------------------------------------------- /client/config/jest/cssTransform.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // This is a custom Jest transformer turning style imports into empty objects. 4 | // http://facebook.github.io/jest/docs/en/webpack.html 5 | 6 | module.exports = { 7 | process() { 8 | return 'module.exports = {};'; 9 | }, 10 | getCacheKey() { 11 | // The output is always the same. 12 | return 'cssTransform'; 13 | }, 14 | }; 15 | -------------------------------------------------------------------------------- /client/config/jest/fileTransform.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const path = require('path'); 4 | 5 | // This is a custom Jest transformer turning file imports into filenames. 6 | // http://facebook.github.io/jest/docs/en/webpack.html 7 | 8 | module.exports = { 9 | process(src, filename) { 10 | const assetFilename = JSON.stringify(path.basename(filename)); 11 | 12 | if (filename.match(/\.svg$/)) { 13 | return `module.exports = { 14 | __esModule: true, 15 | default: ${assetFilename}, 16 | ReactComponent: (props) => ({ 17 | $$typeof: Symbol.for('react.element'), 18 | type: 'svg', 19 | ref: null, 20 | key: null, 21 | props: Object.assign({}, props, { 22 | children: ${assetFilename} 23 | }) 24 | }), 25 | };`; 26 | } 27 | 28 | return `module.exports = ${assetFilename};`; 29 | }, 30 | }; 31 | -------------------------------------------------------------------------------- /client/config/paths.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const path = require('path'); 4 | const fs = require('fs'); 5 | const url = require('url'); 6 | 7 | // Make sure any symlinks in the project folder are resolved: 8 | // https://github.com/facebook/create-react-app/issues/637 9 | const appDirectory = fs.realpathSync(process.cwd()); 10 | const resolveApp = relativePath => path.resolve(appDirectory, relativePath); 11 | 12 | const envPublicUrl = process.env.PUBLIC_URL; 13 | 14 | function ensureSlash(inputPath, needsSlash) { 15 | const hasSlash = inputPath.endsWith('/'); 16 | if (hasSlash && !needsSlash) { 17 | return inputPath.substr(0, inputPath.length - 1); 18 | } else if (!hasSlash && needsSlash) { 19 | return `${inputPath}/`; 20 | } else { 21 | return inputPath; 22 | } 23 | } 24 | 25 | const getPublicUrl = appPackageJson => 26 | envPublicUrl || require(appPackageJson).homepage; 27 | 28 | // We use `PUBLIC_URL` environment variable or "homepage" field to infer 29 | // "public path" at which the app is served. 30 | // Webpack needs to know it to put the right