├── .dockerignore ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── cmd ├── api │ ├── .gitignore │ ├── Dockerfile │ ├── README.md │ ├── cloudbuild.yaml │ └── main.go └── worker │ ├── .gitignore │ ├── Dockerfile │ ├── README.md │ ├── cloudbuild.yaml │ └── main.go ├── docker-compose.yml ├── go.mod ├── go.sum ├── internal └── infra │ ├── docstore.go │ ├── http.go │ ├── logger.go │ └── postgresql.go ├── pkg └── auth │ └── handler.go ├── scripts └── create-schema.sql └── web └── app ├── .env ├── .gitignore ├── README.md ├── cloudbuild.yaml ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.Routes.tsx ├── App.test.tsx ├── App.tsx ├── Components │ ├── Header.tsx │ └── Search.tsx ├── Constants.ts ├── Pages │ ├── Auth │ │ ├── ForgetPasswordPage.tsx │ │ ├── LoginPage.tsx │ │ ├── RegisterPage.tsx │ │ └── Styles.tsx │ ├── IndexPage.tsx │ └── PrivacyPage.tsx ├── http.ts ├── index.css ├── index.tsx ├── react-app-env.d.ts ├── serviceWorker.ts └── setupTests.ts └── tsconfig.json /.dockerignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | *.iml 3 | node_modules/ 4 | runner.conf -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | on: [push] 3 | jobs: 4 | 5 | build: 6 | name: Build 7 | runs-on: ubuntu-latest 8 | steps: 9 | 10 | - uses: actions/checkout@v3 11 | 12 | - uses: actions/setup-go@v3 13 | with: 14 | go-version: '^1.19.0' 15 | 16 | - uses: actions/setup-node@v3 17 | with: 18 | node-version: 16 19 | 20 | - run: go mod download 21 | 22 | - run: npm install --legacy-peer-deps 23 | working-directory: ./web/app 24 | 25 | - run: go test -cover -coverprofile=coverage.txt -covermode=atomic ./... 26 | 27 | # create a CODECOV_TOKEN secret. see https://github.com/marketplace/actions/codecov 28 | #- uses: codecov/codecov-action@v1 29 | # with: 30 | # token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos 31 | 32 | - run: npm run build 33 | working-directory: ./web/app -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | *.iml 3 | tmp/ 4 | .env 5 | coverage.txt -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean init 2 | 3 | init: 4 | go mod download 5 | cd web/app && yarn 6 | 7 | clean: 8 | rm -rf .git 9 | touch .env 10 | 11 | start: 12 | cd web/app && yarn start 13 | 14 | build: 15 | docker build -t myApp/backend -f deployment/backend/Dockerfile . 16 | docker build -t myApp/frontend -f deployment/frontend/Dockerfile . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Go & React Template 2 | 3 | ![ci](https://github.com/rayyildiz/go-react-template/workflows/ci/badge.svg) 4 | 5 | 6 | Simple template for creating [go](https://golang.org) & [react js](https://reactjs.org/) project. 7 | 8 | ```bash 9 | git clone https://github.com/rayyildiz/go-react-template.git my-awesome-app 10 | cd my-awesome-app 11 | make 12 | ``` 13 | 14 | Backend: 15 | --- 16 | 17 | - [PostreSQL](https://github.com/lib/pq) 18 | - [GoCloud](https://gocloud.dev/) 19 | - [Zap Logger](https://github.com/uber-go/zap) with [Sentry support](https://github.com/getsentry/sentry-go) 20 | - [Echo](https://echo.labstack.com/) for routing. 21 | - [Google Cloud Build](https://cloud.google.com/cloud-build) 22 | - [Github Action](https://github.com/features/actions) 23 | 24 | Frontend: 25 | --- 26 | 27 | - [Material UI](https://material-ui.com/) 28 | - Typescript 29 | - React Router Dom 30 | - [Register](web/app/src/Pages/Auth/RegisterPage.tsx), [Login](web/app/src/Pages/Auth/LoginPage.tsx), [Forget Password](web/app/src/Pages/Auth/ForgetPasswordPage.tsx) pages 31 | 32 | ![""](https://images.rayyildiz.dev/go-react-template.png) 33 | 34 | ## Configure 35 | 36 | Run `make clean` to remove `.git` folder and create an empty `.env` file. 37 | 38 | ``` 39 | DEBUG=true 40 | POSTGRES_CONNECTION=postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable 41 | ``` 42 | 43 | # Cloud Run 44 | 45 | This template is configured for [Google CLoud Build](https://console.cloud.google.com/cloud-build/builds) and ready to deploy to [Cloud Run](https://cloud.google.com/run/). 46 | 47 | Useful links: 48 | 49 | - 50 | - 51 | - 52 | -------------------------------------------------------------------------------- /cmd/api/.gitignore: -------------------------------------------------------------------------------- 1 | api 2 | tmp/ -------------------------------------------------------------------------------- /cmd/api/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rayyildiz/ca-certificates 2 | 3 | COPY ./tmp/api . 4 | 5 | CMD ["/apps/api"] 6 | -------------------------------------------------------------------------------- /cmd/api/README.md: -------------------------------------------------------------------------------- 1 | # API 2 | 3 | Required Environments Variables: 4 | 5 | - **PORT** running port ( default: `4000`) 6 | - **SENTRY_DSN** [Sentry](https://sentry.io/organizations/playground-oe/) DNS. Disabled if it is empty(`""`) 7 | - **TRACE_ENABLED** if `true` then enable stackdriver. 8 | - **PROJECT_ID** for stack driver. `TRACE_ENABLED` must be `true` and `PROJECT_ID` must a valid projectId. 9 | -------------------------------------------------------------------------------- /cmd/api/cloudbuild.yaml: -------------------------------------------------------------------------------- 1 | steps: 2 | - name: 'golang' 3 | args: ['go', 'test','-cover','./...'] 4 | - name: 'golang' 5 | args: ['go', 'build', '-a', '-installsuffix','cgo', '-o' ,'tmp/api','.'] 6 | env: ['GO111MODULE=on','CGO_ENABLED=0','GOOS=linux'] 7 | dir: 'cmd/api' 8 | - name: 'gcr.io/cloud-builders/docker' 9 | args: ['build', '-f', 'Dockerfile', '--tag=eu.gcr.io/$PROJECT_ID/api:$SHORT_SHA', '.'] 10 | dir: 'cmd/api' 11 | - name: 'gcr.io/cloud-builders/docker' 12 | args: ['push', 'eu.gcr.io/$PROJECT_ID/api:$SHORT_SHA'] 13 | dir: 'src/api' 14 | # - name: 'gcr.io/cloud-builders/gcloud' 15 | # args: ['run','deploy','api','--image','eu.gcr.io/$PROJECT_ID/api:$SHORT_SHA', '--platform', 'managed','--region','europe-west1'] 16 | -------------------------------------------------------------------------------- /cmd/api/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/getsentry/sentry-go" 5 | "github.com/joho/godotenv" 6 | "go.rayyildiz.dev/app/internal/infra" 7 | "go.rayyildiz.dev/app/pkg/auth" 8 | "go.uber.org/zap" 9 | "os" 10 | "time" 11 | ) 12 | 13 | func init() { 14 | godotenv.Load() 15 | } 16 | 17 | func main() { 18 | log := infra.NewLogger() 19 | defer sentry.Flush(time.Second * 5) 20 | 21 | e := infra.NewHttpRouter(log) 22 | 23 | api := e.Group("/api") 24 | 25 | auth.RegisterHandler(api.Group("/auth"), log) 26 | // register other handlers 27 | 28 | port := os.Getenv("PORT") 29 | if port == "" { 30 | port = "4000" 31 | } 32 | 33 | infra.InitTrace(log, e) 34 | 35 | log.Info("server is starting", zap.String("port", port)) 36 | e.Logger.Fatal(e.Start(":" + port)) 37 | } 38 | -------------------------------------------------------------------------------- /cmd/worker/.gitignore: -------------------------------------------------------------------------------- 1 | worker 2 | tmp/ -------------------------------------------------------------------------------- /cmd/worker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rayyildiz/ca-certificates 2 | 3 | COPY ./tmp/worker . 4 | 5 | CMD ["/apps/worker"] 6 | -------------------------------------------------------------------------------- /cmd/worker/README.md: -------------------------------------------------------------------------------- 1 | # Worker 2 | 3 | Required Environments Variables: 4 | 5 | - **PORT** running port ( default: `4200`) 6 | - **SENTRY_DSN** [Sentry](https://sentry.io/organizations/playground-oe/) DNS. Disabled if it is empty(`""`) 7 | - **TRACE_ENABLED** if `true` then enable stackdriver. 8 | - **PROJECT_ID** for stack driver. `TRACE_ENABLED` must be `true` and `PROJECT_ID` must a valid projectId. 9 | -------------------------------------------------------------------------------- /cmd/worker/cloudbuild.yaml: -------------------------------------------------------------------------------- 1 | steps: 2 | - name: 'golang' 3 | args: ['go', 'test','-cover','./...'] 4 | - name: 'golang' 5 | args: ['go', 'build', '-a', '-installsuffix','cgo', '-o' ,'tmp/worker','.'] 6 | env: ['GO111MODULE=on','CGO_ENABLED=0','GOOS=linux'] 7 | dir: 'cmd/api' 8 | - name: 'gcr.io/cloud-builders/docker' 9 | args: ['build', '-f', 'Dockerfile', '--tag=eu.gcr.io/$PROJECT_ID/worker:$SHORT_SHA', '.'] 10 | dir: 'cmd/api' 11 | - name: 'gcr.io/cloud-builders/docker' 12 | args: ['push', 'eu.gcr.io/$PROJECT_ID/worker:$SHORT_SHA'] 13 | dir: 'src/api' 14 | # - name: 'gcr.io/cloud-builders/gcloud' 15 | # args: ['run','deploy','worker','--image','eu.gcr.io/$PROJECT_ID/worker:$SHORT_SHA', '--platform', 'managed','--region','europe-west1'] 16 | -------------------------------------------------------------------------------- /cmd/worker/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/getsentry/sentry-go" 5 | "github.com/joho/godotenv" 6 | "go.rayyildiz.dev/app/internal/infra" 7 | "go.uber.org/zap" 8 | "os" 9 | "time" 10 | ) 11 | 12 | func init() { 13 | godotenv.Load() 14 | } 15 | 16 | func main() { 17 | log := infra.NewLogger() 18 | defer sentry.Flush(time.Second * 5) 19 | 20 | e := infra.NewHttpRouter(log) 21 | 22 | port := os.Getenv("PORT") 23 | if port == "" { 24 | port = "4200" 25 | } 26 | 27 | infra.InitTrace(log, e) 28 | 29 | log.Info("server is starting", zap.String("port", port)) 30 | e.Logger.Fatal(e.Start(":" + port)) 31 | } 32 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | postgres: 5 | container_name: app_db 6 | image: postgres:11 7 | ports: 8 | - "5432:5432" 9 | environment: 10 | POSTGRES_USER: "postgres" 11 | POSTGRES_PASSWORD: "postgres" 12 | POSTGRES_DB: "postgres" 13 | volumes: 14 | - appdb_data:/var/lib/postgresql/data 15 | 16 | volumes: 17 | appdb_data: {} 18 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module go.rayyildiz.dev/app 2 | 3 | go 1.19 4 | 5 | require ( 6 | contrib.go.opencensus.io/exporter/stackdriver v0.13.14 7 | github.com/getsentry/sentry-go v0.18.0 8 | github.com/joho/godotenv v1.5.1 9 | github.com/labstack/echo/v4 v4.10.0 10 | github.com/lib/pq v1.10.7 11 | go.opencensus.io v0.24.0 12 | go.uber.org/zap v1.24.0 13 | gocloud.dev v0.28.0 14 | ) 15 | 16 | require ( 17 | cloud.google.com/go/compute v1.18.0 // indirect 18 | cloud.google.com/go/compute/metadata v0.2.3 // indirect 19 | cloud.google.com/go/monitoring v1.12.0 // indirect 20 | cloud.google.com/go/trace v1.8.0 // indirect 21 | github.com/aws/aws-sdk-go v1.44.204 // indirect 22 | github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect 23 | github.com/golang-jwt/jwt v3.2.2+incompatible // indirect 24 | github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect 25 | github.com/golang/protobuf v1.5.2 // indirect 26 | github.com/google/go-cmp v0.5.9 // indirect 27 | github.com/google/uuid v1.3.0 // indirect 28 | github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect 29 | github.com/googleapis/gax-go/v2 v2.7.0 // indirect 30 | github.com/jmespath/go-jmespath v0.4.0 // indirect 31 | github.com/labstack/gommon v0.4.0 // indirect 32 | github.com/mattn/go-colorable v0.1.13 // indirect 33 | github.com/mattn/go-isatty v0.0.17 // indirect 34 | github.com/prometheus/prometheus v0.42.0 // indirect 35 | github.com/valyala/bytebufferpool v1.0.0 // indirect 36 | github.com/valyala/fasttemplate v1.2.2 // indirect 37 | go.uber.org/atomic v1.10.0 // indirect 38 | go.uber.org/multierr v1.9.0 // indirect 39 | golang.org/x/crypto v0.6.0 // indirect 40 | golang.org/x/net v0.7.0 // indirect 41 | golang.org/x/oauth2 v0.5.0 // indirect 42 | golang.org/x/sync v0.1.0 // indirect 43 | golang.org/x/sys v0.5.0 // indirect 44 | golang.org/x/text v0.7.0 // indirect 45 | golang.org/x/time v0.3.0 // indirect 46 | golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect 47 | google.golang.org/api v0.110.0 // indirect 48 | google.golang.org/appengine v1.6.7 // indirect 49 | google.golang.org/genproto v0.0.0-20230216225411-c8e22ba71e44 // indirect 50 | google.golang.org/grpc v1.53.0 // indirect 51 | google.golang.org/protobuf v1.28.1 // indirect 52 | ) 53 | -------------------------------------------------------------------------------- /internal/infra/docstore.go: -------------------------------------------------------------------------------- 1 | package infra 2 | 3 | import ( 4 | "context" 5 | "errors" 6 | 7 | "gocloud.dev/docstore" 8 | _ "gocloud.dev/docstore/memdocstore" // in-mem doctsore 9 | // add other docstore, more informatin: https://gocloud.dev/howto/docstore/ 10 | ) 11 | 12 | var ( 13 | ErrDocStoreCollectionEmpty = errors.New("$DOCSTORE_COLLECTION can't be nil") 14 | ) 15 | 16 | func NewDocStore(collection string) (*docstore.Collection, error) { 17 | if collection == "" { 18 | return nil, ErrDocStoreCollectionEmpty 19 | } 20 | 21 | return docstore.OpenCollection(context.Background(), collection) 22 | } 23 | -------------------------------------------------------------------------------- /internal/infra/http.go: -------------------------------------------------------------------------------- 1 | package infra 2 | 3 | import ( 4 | "net/http" 5 | "os" 6 | 7 | "github.com/getsentry/sentry-go" 8 | sentryecho "github.com/getsentry/sentry-go/echo" 9 | "github.com/labstack/echo/v4" 10 | "github.com/labstack/echo/v4/middleware" 11 | "go.opencensus.io/plugin/ochttp" 12 | "go.uber.org/zap" 13 | ) 14 | 15 | func NewHttpRouter(log *zap.Logger) *echo.Echo { 16 | e := echo.New() 17 | e.HideBanner = true 18 | 19 | e.Use(middleware.Recover()) 20 | e.Use(middleware.RequestID()) 21 | e.Use(zapLogger(log)) 22 | e.Use(middleware.CORSWithConfig(middleware.CORSConfig{ 23 | AllowOrigins: []string{ 24 | "http://localhost:3000", 25 | }, 26 | AllowMethods: []string{http.MethodOptions, http.MethodHead, http.MethodPost, http.MethodGet}, 27 | })) 28 | 29 | dsn := os.Getenv("SENTRY_DSN") 30 | if len(dsn) > 0 { 31 | err := sentry.Init(sentry.ClientOptions{ 32 | Dsn: dsn, 33 | Environment: "prod", 34 | }) 35 | if err != nil { 36 | log.Error("infra.NewHttpRouter, sentry-init", zap.Error(err)) 37 | } 38 | 39 | e.Use(sentryecho.New(sentryecho.Options{})) 40 | } 41 | 42 | return e 43 | } 44 | 45 | func newCensus() echo.MiddlewareFunc { 46 | return func(next echo.HandlerFunc) echo.HandlerFunc { 47 | return func(c echo.Context) (err error) { 48 | handler := &ochttp.Handler{ 49 | Handler: http.HandlerFunc( 50 | func(w http.ResponseWriter, r *http.Request) { 51 | c.SetRequest(r) 52 | c.SetResponse(echo.NewResponse(w, c.Echo())) 53 | err = next(c) 54 | }, 55 | ), 56 | } 57 | handler.ServeHTTP(c.Response(), c.Request()) 58 | return 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /internal/infra/logger.go: -------------------------------------------------------------------------------- 1 | package infra 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | 7 | "github.com/labstack/echo/v4" 8 | "go.uber.org/zap" 9 | "go.uber.org/zap/zapcore" 10 | 11 | "contrib.go.opencensus.io/exporter/stackdriver" 12 | "go.opencensus.io/plugin/ochttp" 13 | "go.opencensus.io/trace" 14 | 15 | "os" 16 | ) 17 | 18 | func NewLogger() *zap.Logger { 19 | logger, err := zap.NewProductionConfig().Build() 20 | if err != nil { 21 | fmt.Printf("Coudl not create zap logger, %v\n", err) 22 | return nil 23 | } 24 | return logger 25 | } 26 | 27 | func InitTrace(log *zap.Logger, e *echo.Echo) { 28 | projectId := os.Getenv("PROJECT_ID") 29 | 30 | if os.Getenv("TRACE_ENABLED") == "true" && len(projectId) > 0 { 31 | log.Info("opencensus is enabled") 32 | exporter, err := stackdriver.NewExporter(stackdriver.Options{ 33 | ProjectID: projectId, 34 | }) 35 | if err == nil { 36 | trace.RegisterExporter(exporter) 37 | } else { 38 | log.Error("infra:InitTrace", zap.Error(err)) 39 | } 40 | trace.ApplyConfig(trace.Config{DefaultSampler: trace.AlwaysSample()}) 41 | 42 | e.Use(newCensus()) 43 | 44 | var ocHandler = &ochttp.Handler{Handler: e, IsPublicEndpoint: true} 45 | e.Server.Handler = ocHandler 46 | } 47 | } 48 | 49 | func zapLogger(log *zap.Logger) echo.MiddlewareFunc { 50 | return func(next echo.HandlerFunc) echo.HandlerFunc { 51 | return func(c echo.Context) error { 52 | start := time.Now() 53 | 54 | err := next(c) 55 | if err != nil { 56 | c.Error(err) 57 | } 58 | 59 | req := c.Request() 60 | res := c.Response() 61 | 62 | id := req.Header.Get(echo.HeaderXRequestID) 63 | if id == "" { 64 | id = res.Header().Get(echo.HeaderXRequestID) 65 | } 66 | 67 | fields := []zapcore.Field{ 68 | zap.Int("status", res.Status), 69 | zap.String("latency", time.Since(start).String()), 70 | zap.String("id", id), 71 | zap.String("method", req.Method), 72 | zap.String("uri", req.RequestURI), 73 | zap.String("host", req.Host), 74 | zap.String("remote_ip", c.RealIP()), 75 | } 76 | if err != nil { 77 | fields = append(fields, zap.Error(err)) 78 | } 79 | 80 | n := res.Status 81 | switch { 82 | case n >= 500: 83 | log.Error("Server error", fields...) 84 | case n >= 400: 85 | log.Warn("Client error", fields...) 86 | case n >= 300: 87 | log.Info("Redirection", fields...) 88 | default: 89 | log.Info("Success", fields...) 90 | } 91 | 92 | return nil 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /internal/infra/postgresql.go: -------------------------------------------------------------------------------- 1 | package infra 2 | 3 | import ( 4 | "database/sql" 5 | "errors" 6 | _ "github.com/lib/pq" 7 | ) 8 | 9 | func NewDatabase(connStr string) (*sql.DB, error) { 10 | if connStr == "" { 11 | return nil, errors.New("please provide a db connection string") 12 | } 13 | 14 | // postgres://postgres:123456@localhost/postgres?sslmode=disable 15 | 16 | db, err := sql.Open("postgres", connStr) 17 | if err != nil { 18 | return nil, err 19 | } 20 | 21 | db.SetMaxIdleConns(10) 22 | db.SetMaxOpenConns(4) 23 | 24 | err = db.Ping() 25 | return db, err 26 | } 27 | -------------------------------------------------------------------------------- /pkg/auth/handler.go: -------------------------------------------------------------------------------- 1 | package auth 2 | 3 | import ( 4 | "github.com/labstack/echo/v4" 5 | "go.uber.org/zap" 6 | ) 7 | 8 | func RegisterHandler(e *echo.Group, log *zap.Logger) { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /scripts/create-schema.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE IF NOT EXISTS users 2 | ( 3 | email text primary key, 4 | password text not null, 5 | full_name text, 6 | profile_photo text, 7 | created_at timestamp default now(), 8 | updated_at timestamp default now(), 9 | verified boolean default false, 10 | deleted_at timestamp 11 | ); -------------------------------------------------------------------------------- /web/app/.env: -------------------------------------------------------------------------------- 1 | BROWSER=none 2 | -------------------------------------------------------------------------------- /web/app/.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 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /web/app/README.md: -------------------------------------------------------------------------------- 1 | # React with Typescript 2 | 3 | 4 | -------------------------------------------------------------------------------- /web/app/cloudbuild.yaml: -------------------------------------------------------------------------------- 1 | steps: 2 | - name: 'gcr.io/cloud-builders/npm' 3 | args: ['ci'] 4 | dir: 'web/app' 5 | - name: 'gcr.io/cloud-builders/npm' 6 | args: ['run','build'] 7 | dir: 'web/app' 8 | # - name: 'gcr.io/cloud-builders/gsutil' 9 | # args: ['rsync', '-R', 'build','gs://your-public-bucket.com'] 10 | # dir: 'web/app' 11 | 12 | -------------------------------------------------------------------------------- /web/app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "proxy": "http://localhost:4000", 6 | "dependencies": { 7 | "@material-ui/core": "^4.12.4", 8 | "@material-ui/icons": "^4.11.3", 9 | "@material-ui/lab": "^4.0.0-alpha.61", 10 | "@material-ui/styles": "^4.11.5", 11 | "@testing-library/jest-dom": "^5.16.4", 12 | "@testing-library/react": "^13.1.1", 13 | "@testing-library/user-event": "^14.1.0", 14 | "@types/jest": "^27.4.1", 15 | "@types/node": "^17.0.24", 16 | "@types/react": "^18.0.5", 17 | "@types/react-dom": "^18.0.1", 18 | "@types/react-router-dom": "^5.3.3", 19 | "async": "^3.2.3", 20 | "es6-promise": "^4.2.8", 21 | "nth-check": "^2.0.1", 22 | "react": "^18.0.0", 23 | "react-dom": "^18.0.0", 24 | "react-router-dom": "^6.3.0", 25 | "react-scripts": "5.0.1", 26 | "typeface-roboto": "^1.1.13", 27 | "typescript": "^4.6.3", 28 | "whatwg-fetch": "^3.6.2" 29 | }, 30 | "scripts": { 31 | "start": "react-scripts start", 32 | "build": "react-scripts build", 33 | "test": "react-scripts test", 34 | "eject": "react-scripts eject" 35 | }, 36 | "eslintConfig": { 37 | "extends": "react-app" 38 | }, 39 | "browserslist": { 40 | "production": [ 41 | ">0.2%", 42 | "not dead", 43 | "not op_mini all" 44 | ], 45 | "development": [ 46 | "last 1 chrome version", 47 | "last 1 firefox version", 48 | "last 1 safari version" 49 | ] 50 | }, 51 | "devDependencies": { 52 | "dotenv": "^16.0.0" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /web/app/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rayyildiz/go-react-template/bb94e4173ff180753a8cbb5d56b9ec5ee9616bfd/web/app/public/favicon.ico -------------------------------------------------------------------------------- /web/app/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 14 | React App 15 | 16 | 17 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /web/app/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rayyildiz/go-react-template/bb94e4173ff180753a8cbb5d56b9ec5ee9616bfd/web/app/public/logo192.png -------------------------------------------------------------------------------- /web/app/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rayyildiz/go-react-template/bb94e4173ff180753a8cbb5d56b9ec5ee9616bfd/web/app/public/logo512.png -------------------------------------------------------------------------------- /web/app/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App 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 | -------------------------------------------------------------------------------- /web/app/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | -------------------------------------------------------------------------------- /web/app/src/App.Routes.tsx: -------------------------------------------------------------------------------- 1 | import {FC} from "react"; 2 | import {Route, Routes} from "react-router-dom"; 3 | import {IndexPage} from "./Pages/IndexPage"; 4 | import {LoginPage} from "./Pages/Auth/LoginPage"; 5 | import {RegisterPage} from "./Pages/Auth/RegisterPage"; 6 | import {ForgetPasswordPage} from "./Pages/Auth/ForgetPasswordPage"; 7 | import {PrivacyPage} from "./Pages/PrivacyPage"; 8 | 9 | type AppRoutesProps = {} 10 | 11 | export const AppRoutes: FC = (props) => { 12 | return ( 13 | 14 | }/> 15 | }/> 16 | }/> 17 | }/> 18 | }/> 19 | 20 | ) 21 | }; 22 | -------------------------------------------------------------------------------- /web/app/src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import { render } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | const { getByText } = render(); 6 | const linkElement = getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /web/app/src/App.tsx: -------------------------------------------------------------------------------- 1 | import {BrowserRouter} from "react-router-dom"; 2 | import {Container, createStyles, CssBaseline, makeStyles, Theme, ThemeProvider} from "@material-ui/core"; 3 | import {AppRoutes} from "./App.Routes"; 4 | import {Header} from "./Components/Header"; 5 | import {createMuiTheme} from '@material-ui/core/styles'; 6 | import {deepOrange, red} from "@material-ui/core/colors"; 7 | 8 | 9 | const theme = createMuiTheme({ 10 | palette: { 11 | primary: red, 12 | secondary: deepOrange, 13 | }, 14 | }); 15 | 16 | const useStyles = makeStyles((theme: Theme) => 17 | createStyles({ 18 | main: { 19 | paddingLeft: 0, 20 | paddingRight: 0 21 | }, 22 | paper: { 23 | marginTop: theme.spacing(2), 24 | display: 'flex', 25 | flexDirection: 'column', 26 | marginRight: theme.spacing(4), 27 | marginLeft: theme.spacing(4), 28 | }, 29 | })); 30 | 31 | const App: React.FC = () => { 32 | const classes = useStyles(); 33 | 34 | return ( 35 | 36 | 37 | 38 | 39 |
40 |
41 | 42 |
43 | 44 | 45 | 46 | ); 47 | }; 48 | 49 | export default App; 50 | -------------------------------------------------------------------------------- /web/app/src/Components/Header.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import {AppBar, Button, createStyles, IconButton, makeStyles, Theme, Toolbar, Typography} from "@material-ui/core"; 3 | import HomeIcon from '@material-ui/icons/Home'; 4 | import {useNavigate} from "react-router-dom"; 5 | import {Search} from "./Search"; 6 | 7 | const useStyles = makeStyles((theme: Theme) => 8 | createStyles({ 9 | root: { 10 | flexGrow: 1, 11 | }, 12 | menuButton: { 13 | marginRight: theme.spacing(2), 14 | }, 15 | title: { 16 | flexGrow: 1, 17 | display: 'none', 18 | [theme.breakpoints.up('sm')]: { 19 | display: 'block', 20 | }, 21 | cursor: 'pointer', 22 | }, 23 | }), 24 | ); 25 | 26 | export const Header = () => { 27 | const classes = useStyles(); 28 | const navigate = useNavigate(); 29 | 30 | return ( 31 |
32 | 33 | 34 | navigate("/")}> 35 | 36 | 37 | 38 | navigate("/")}> 39 | Go React Template 40 | 41 | 42 | 43 | 44 | 45 | 46 |
47 | ) 48 | }; 49 | -------------------------------------------------------------------------------- /web/app/src/Components/Search.tsx: -------------------------------------------------------------------------------- 1 | import React, {FC, FormEvent, useState} from "react"; 2 | import SearchIcon from "@material-ui/icons/Search"; 3 | import {createStyles, fade, InputBase, makeStyles, Theme} from "@material-ui/core"; 4 | 5 | 6 | const useStyles = makeStyles((theme: Theme) => 7 | createStyles({ 8 | root: { 9 | flexGrow: 1, 10 | }, 11 | menuButton: { 12 | marginRight: theme.spacing(2), 13 | }, 14 | title: { 15 | flexGrow: 1, 16 | display: 'none', 17 | [theme.breakpoints.up('sm')]: { 18 | display: 'block', 19 | }, 20 | cursor: 'pointer', 21 | }, 22 | search: { 23 | position: 'relative', 24 | borderRadius: theme.shape.borderRadius, 25 | backgroundColor: fade(theme.palette.common.white, 0.15), 26 | '&:hover': { 27 | backgroundColor: fade(theme.palette.common.white, 0.25), 28 | }, 29 | marginLeft: 0, 30 | width: '100%', 31 | [theme.breakpoints.up('sm')]: { 32 | marginLeft: theme.spacing(1), 33 | width: 'auto', 34 | }, 35 | }, 36 | searchIcon: { 37 | width: theme.spacing(7), 38 | height: '100%', 39 | position: 'absolute', 40 | pointerEvents: 'none', 41 | display: 'flex', 42 | alignItems: 'center', 43 | justifyContent: 'center', 44 | }, 45 | inputRoot: { 46 | color: 'inherit', 47 | }, 48 | inputInput: { 49 | padding: theme.spacing(1, 1, 1, 7), 50 | transition: theme.transitions.create('width'), 51 | width: '100%', 52 | [theme.breakpoints.up('sm')]: { 53 | width: 180, 54 | '&:focus': { 55 | width: 240, 56 | }, 57 | }, 58 | }, 59 | }), 60 | ); 61 | 62 | 63 | type SearchProps = {} 64 | 65 | 66 | export const Search: FC = (props) => { 67 | const classes = useStyles(); 68 | const [searchTerm, setSearchTerm] = useState(""); 69 | 70 | const doSearch = async (e: FormEvent) => { 71 | e.preventDefault(); 72 | }; 73 | 74 | return ( 75 |
76 |
77 | 78 |
79 |
80 | setSearchTerm(event.target.value)} 89 | /> 90 | 91 |
92 | ) 93 | }; 94 | -------------------------------------------------------------------------------- /web/app/src/Constants.ts: -------------------------------------------------------------------------------- 1 | export const API_BASE_URL = "/api"; 2 | export const LOCALSTORAGE_TOKEN = "user.token"; 3 | export const ENABLE_SW = false; 4 | -------------------------------------------------------------------------------- /web/app/src/Pages/Auth/ForgetPasswordPage.tsx: -------------------------------------------------------------------------------- 1 | import {FC, FormEvent, useState} from "react"; 2 | import {useLoginStyles} from "./Styles"; 3 | import Avatar from '@material-ui/core/Avatar'; 4 | import Button from '@material-ui/core/Button'; 5 | import TextField from '@material-ui/core/TextField'; 6 | import Grid from '@material-ui/core/Grid'; 7 | import LockOutlinedIcon from '@material-ui/icons/LockOutlined'; 8 | import Typography from '@material-ui/core/Typography'; 9 | import {Backdrop, CircularProgress, Container, Link} from "@material-ui/core"; 10 | import {Link as RouterLink} from 'react-router-dom'; 11 | import {Alert} from '@material-ui/lab'; 12 | import {API_BASE_URL} from "../../Constants"; 13 | import {http} from "../../http"; 14 | 15 | type ForgetPasswordPageProps = {} 16 | 17 | interface ForgetPasswordResponse { 18 | token: string; 19 | } 20 | 21 | export const ForgetPasswordPage: FC = (props) => { 22 | const classes = useLoginStyles(); 23 | const [loading, setLoading] = useState(false); 24 | const [error, setError] = useState(""); 25 | 26 | const [email, setEmail] = useState(''); 27 | 28 | const handleFormSubmit = async (e: FormEvent) => { 29 | e.preventDefault(); 30 | 31 | try { 32 | setLoading(true); 33 | const response = await http(API_BASE_URL + "/auth/reminder", "POST", { 34 | "email": email, 35 | }); 36 | console.log("Response ", response.parsedBody) 37 | } catch (ex) { 38 | if (ex instanceof Error) setError(ex.toString()); 39 | } finally { 40 | setLoading(false); 41 | } 42 | }; 43 | 44 | return ( 45 | 46 |
47 | 48 | 49 | 50 | 51 | Reset Password 52 | 53 |
54 | 55 | {error.length > 0 && {error}} 56 | 57 | 58 | setEmail(event.target.value)} 70 | /> 71 | 72 | 73 | 83 | 84 | 85 | 86 | 87 | 88 | Already have an account? Sign in 89 | 90 | 91 | 92 | 93 | 94 | 97 | 98 | 99 |
100 |
101 |
102 | ) 103 | }; 104 | -------------------------------------------------------------------------------- /web/app/src/Pages/Auth/LoginPage.tsx: -------------------------------------------------------------------------------- 1 | import {FC, FormEvent, useState} from "react"; 2 | import {useLoginStyles} from "./Styles"; 3 | import Avatar from '@material-ui/core/Avatar'; 4 | import Button from '@material-ui/core/Button'; 5 | import TextField from '@material-ui/core/TextField'; 6 | import FormControlLabel from '@material-ui/core/FormControlLabel'; 7 | import Checkbox from '@material-ui/core/Checkbox'; 8 | import Grid from '@material-ui/core/Grid'; 9 | import LockOutlinedIcon from '@material-ui/icons/LockOutlined'; 10 | import Typography from '@material-ui/core/Typography'; 11 | import {Backdrop, CircularProgress, Container, Link} from "@material-ui/core"; 12 | import {Link as RouterLink} from 'react-router-dom'; 13 | import {Alert} from '@material-ui/lab'; 14 | import {http} from "../../http"; 15 | import {API_BASE_URL} from "../../Constants"; 16 | 17 | type LoginPageProps = {} 18 | 19 | type FormState = { 20 | email: string; 21 | password: string; 22 | } 23 | 24 | interface LoginResponse { 25 | status: boolean; 26 | token?: string; 27 | displayName?: string; 28 | } 29 | 30 | 31 | export const LoginPage: FC = (props) => { 32 | const classes = useLoginStyles(); 33 | const [loading, setLoading] = useState(false); 34 | const [error, setError] = useState(""); 35 | 36 | const [form, setForm] = useState({ 37 | email: '', 38 | password: '' 39 | }); 40 | 41 | const handleFormSubmit = async (e: FormEvent) => { 42 | e.preventDefault(); 43 | try { 44 | setLoading(true); 45 | const response = await http(API_BASE_URL + "/auth/login", "POST",{ 46 | "email": form.email, 47 | "password": form.password 48 | }); 49 | console.log("Response ", response.parsedBody) 50 | } catch (ex) { 51 | if (ex instanceof Error )setError(ex.toString()); 52 | } finally { 53 | setLoading(false); 54 | } 55 | }; 56 | 57 | return ( 58 | 59 |
60 | 61 | 62 | 63 | 64 | Sign in 65 | 66 | 67 |
68 | 69 | {error.length > 0 && {error}} 70 | 71 | 72 | setForm({...form, email: event.target.value}))} 84 | /> 85 | 86 | 87 | setForm({...form, password: event.target.value}))} 99 | /> 100 | 101 | 102 | } 104 | label="Remember me" 105 | /> 106 | 107 | 108 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | Forgot password? 125 | 126 | 127 | 128 | 129 | {"Don't have an account? Sign Up"} 130 | 131 | 132 | 133 | 134 | 135 | 138 | 139 | 140 | 141 |
142 |
143 |
144 | ) 145 | 146 | }; 147 | -------------------------------------------------------------------------------- /web/app/src/Pages/Auth/RegisterPage.tsx: -------------------------------------------------------------------------------- 1 | import {FC, FormEvent, useState} from "react"; 2 | import {useLoginStyles} from "./Styles"; 3 | import Avatar from '@material-ui/core/Avatar'; 4 | import Button from '@material-ui/core/Button'; 5 | import TextField from '@material-ui/core/TextField'; 6 | import Grid from '@material-ui/core/Grid'; 7 | import LockOutlinedIcon from '@material-ui/icons/LockOutlined'; 8 | import Typography from '@material-ui/core/Typography'; 9 | import {Backdrop, CircularProgress, Container, Link} from "@material-ui/core"; 10 | import {Link as RouterLink} from 'react-router-dom'; 11 | import {Alert} from '@material-ui/lab'; 12 | import {API_BASE_URL} from "../../Constants"; 13 | import {http} from "../../http"; 14 | 15 | type RegisterPageProps = {} 16 | 17 | 18 | type FormState = { 19 | email: string; 20 | password: string; 21 | password2: string; 22 | } 23 | 24 | interface RegisterResponse { 25 | status: boolean 26 | } 27 | 28 | export const RegisterPage: FC = (props) => { 29 | const classes = useLoginStyles(); 30 | const [loading, setLoading] = useState(false); 31 | const [error, setError] = useState(""); 32 | 33 | const [form, setForm] = useState({ 34 | email: "", 35 | password: "", 36 | password2: "", 37 | }); 38 | 39 | const handleFormSubmit = async (e: FormEvent) => { 40 | e.preventDefault(); 41 | try { 42 | setLoading(true); 43 | 44 | const response = await http(API_BASE_URL + "/auth/register", "POST", { 45 | "email": form.email, 46 | "password": form.password, 47 | "password2": form.password2 48 | }); 49 | console.log("Response ", response.parsedBody) 50 | } catch (ex) { 51 | if ( ex instanceof Error) setError(ex.toString()); 52 | } finally { 53 | setLoading(false); 54 | } 55 | }; 56 | 57 | return ( 58 | 59 |
60 | 61 | 62 | 63 | 64 | Sign up 65 | 66 |
67 | 68 | {error.length > 0 && {error}} 69 | 70 | 71 | setForm({...form, email: event.target.value}))} 81 | /> 82 | 83 | 84 | setForm({...form, password: event.target.value}))} 94 | /> 95 | 96 | 97 | setForm({...form, password2: event.target.value}))} 107 | /> 108 | 109 | 110 | 120 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | Already have an account? Sign in 130 | 131 | 132 | 133 |
134 |
135 |
136 | ) 137 | 138 | }; 139 | -------------------------------------------------------------------------------- /web/app/src/Pages/Auth/Styles.tsx: -------------------------------------------------------------------------------- 1 | import {createStyles, makeStyles, Theme} from "@material-ui/core"; 2 | 3 | export const useLoginStyles = makeStyles((theme: Theme) => 4 | createStyles({ 5 | paper: { 6 | marginTop: theme.spacing(8), 7 | display: 'flex', 8 | flexDirection: 'column', 9 | alignItems: 'center', 10 | }, 11 | avatar: { 12 | margin: theme.spacing(1), 13 | backgroundColor: theme.palette.secondary.main, 14 | }, 15 | form: { 16 | width: '100%', 17 | marginTop: theme.spacing(3), 18 | }, 19 | submit: { 20 | margin: theme.spacing(3, 0, 2), 21 | }, 22 | backdrop: { 23 | zIndex: theme.zIndex.drawer + 1, 24 | color: '#fff', 25 | }, 26 | }), 27 | ); 28 | -------------------------------------------------------------------------------- /web/app/src/Pages/IndexPage.tsx: -------------------------------------------------------------------------------- 1 | import {FC} from "react"; 2 | 3 | 4 | type IndexPageProps = {} 5 | 6 | 7 | export const IndexPage: FC = (props) => { 8 | 9 | 10 | return ( 11 |
12 |

Home page

13 |
14 | ) 15 | }; 16 | -------------------------------------------------------------------------------- /web/app/src/Pages/PrivacyPage.tsx: -------------------------------------------------------------------------------- 1 | export const PrivacyPage = () => ( 2 |
3 |

What are cookies?

4 | 5 |

As is common practice with almost all professional websites this site uses cookies, which are tiny files that are downloaded to your computer, to improve your experience. This page describes what information they gather, how we 6 | use it and why we sometimes need to store these cookies. We will also share how you can prevent these cookies from being stored however this may downgrade or 'break' certain elements of the sites functionality. 7 |

8 |

9 | For more general information on cookies see the Wikipedia article on HTTP Cookies.

10 |

How We Use Cookies

11 |

We use cookies for a variety of reasons detailed below. Unfortunately in most cases there are no industry standard options for disabling cookies without completely disabling the functionality and features they add to this site. 12 | It is recommended that you leave on all cookies if you are not sure whether you need them or not in case they are used to provide a service that you use.

13 | 14 |

Disabling Cookies

15 |

You can prevent the setting of cookies by adjusting the settings on your browser (see your browser Help for how to do this). Be aware that disabling cookies will affect the functionality of this and many other websites that you 16 | visit. Disabling cookies will usually result in also disabling certain functionality and features of the this site. Therefore it is recommended that you do not disable cookies.

17 | 18 |

The Cookies We Set

19 |
    20 |
  • Site preferences cookies
  • 21 |
22 |

In order to provide you with a great experience on this site we provide the functionality to set your preferences for how this site runs when you use it. In order to remember your preferences we need to set cookies so that this 23 | information can be called whenever you interact with a page is affected by your preferences.

24 | 25 | 26 |

Third Party Cookies

27 |

In some special cases we also use cookies provided by trusted third parties. The following section details which third party cookies you might encounter through this site.

28 |
    29 |
  • Third party analytics are used to track and measure usage of this site so that we can continue to produce engaging content. These cookies may track things such as how long you spend on the site or pages you visit which helps 30 | us to understand how we can improve the site for you. 31 |
  • 32 |
  • We use adverts to offset the costs of running this site and provide funding for further development. The behavioural advertising cookies used by this site are designed to ensure that we provide you with the most relevant 33 | adverts where possible by anonymously tracking your interests and presenting similar things that may be of interest. 34 |
  • 35 |
36 |
37 | ); 38 | -------------------------------------------------------------------------------- /web/app/src/http.ts: -------------------------------------------------------------------------------- 1 | import {LOCALSTORAGE_TOKEN} from "./Constants"; 2 | 3 | export interface IHttpResponse extends Response { 4 | parsedBody?: T; 5 | } 6 | 7 | 8 | export const http = (url: string, method: string, body?: any, contentType: string = "application/json"): Promise> => { 9 | 10 | const request = new Request(url, { 11 | method: method, 12 | body: body ? JSON.stringify(body) : null 13 | }); 14 | request.headers.set("Content-Type", contentType); 15 | 16 | const token = localStorage.getItem(LOCALSTORAGE_TOKEN); 17 | if (token != null) { 18 | request.headers.set("Authorization", "Bearer " + token); 19 | } 20 | 21 | return new Promise((resolve, reject) => { 22 | let response: IHttpResponse; 23 | fetch(request) 24 | .then(res => { 25 | response = res; 26 | return res.json(); 27 | }) 28 | .then(body => { 29 | if (response.ok) { 30 | response.parsedBody = body; 31 | resolve(response); 32 | } else { 33 | reject(response); 34 | } 35 | }) 36 | .catch(err => { 37 | reject(err); 38 | }); 39 | }); 40 | }; 41 | -------------------------------------------------------------------------------- /web/app/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /web/app/src/index.tsx: -------------------------------------------------------------------------------- 1 | import ReactDOM from 'react-dom'; 2 | import './index.css'; 3 | import App from './App'; 4 | import * as serviceWorker from './serviceWorker'; 5 | import 'typeface-roboto'; 6 | import {ENABLE_SW} from "./Constants"; 7 | import 'whatwg-fetch'; 8 | import 'es6-promise/auto'; 9 | 10 | ReactDOM.render(, document.getElementById('root')); 11 | 12 | if (ENABLE_SW) { 13 | serviceWorker.register(); 14 | } else { 15 | serviceWorker.unregister(); 16 | } 17 | -------------------------------------------------------------------------------- /web/app/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /web/app/src/serviceWorker.ts: -------------------------------------------------------------------------------- 1 | const isLocalhost = Boolean( 2 | window.location.hostname === 'localhost' || 3 | window.location.hostname === '[::1]' || 4 | window.location.hostname.match( 5 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 6 | ) 7 | ); 8 | 9 | type Config = { 10 | onSuccess?: (registration: ServiceWorkerRegistration) => void; 11 | onUpdate?: (registration: ServiceWorkerRegistration) => void; 12 | }; 13 | 14 | export function register(config?: Config) { 15 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 16 | const publicUrl = new URL( 17 | process.env.PUBLIC_URL, 18 | window.location.href 19 | ); 20 | if (publicUrl.origin !== window.location.origin) { 21 | return; 22 | } 23 | 24 | window.addEventListener('load', () => { 25 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 26 | 27 | if (isLocalhost) { 28 | checkValidServiceWorker(swUrl, config); 29 | navigator.serviceWorker.ready.then(() => { 30 | console.log( 31 | 'This web app is being served cache-first by a service ' + 32 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 33 | ); 34 | }); 35 | } else { 36 | registerValidSW(swUrl, config); 37 | } 38 | }); 39 | } 40 | } 41 | 42 | function registerValidSW(swUrl: string, config?: Config) { 43 | navigator.serviceWorker 44 | .register(swUrl) 45 | .then(registration => { 46 | registration.onupdatefound = () => { 47 | const installingWorker = registration.installing; 48 | if (installingWorker == null) { 49 | return; 50 | } 51 | installingWorker.onstatechange = () => { 52 | if (installingWorker.state === 'installed') { 53 | if (navigator.serviceWorker.controller) { 54 | console.log( 55 | 'New content is available and will be used when all ' + 56 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 57 | ); 58 | 59 | if (config && config.onUpdate) { 60 | config.onUpdate(registration); 61 | } 62 | } else { 63 | console.log('Content is cached for offline use.'); 64 | 65 | if (config && config.onSuccess) { 66 | config.onSuccess(registration); 67 | } 68 | } 69 | } 70 | }; 71 | }; 72 | }) 73 | .catch(error => { 74 | console.error('Error during service worker registration:', error); 75 | }); 76 | } 77 | 78 | function checkValidServiceWorker(swUrl: string, config?: Config) { 79 | fetch(swUrl, { 80 | headers: {'Service-Worker': 'script'} 81 | }) 82 | .then(response => { 83 | const contentType = response.headers.get('content-type'); 84 | if ( 85 | response.status === 404 || 86 | (contentType != null && contentType.indexOf('javascript') === -1) 87 | ) { 88 | navigator.serviceWorker.ready.then(registration => { 89 | registration.unregister().then(() => { 90 | window.location.reload(); 91 | }); 92 | }); 93 | } else { 94 | registerValidSW(swUrl, config); 95 | } 96 | }) 97 | .catch(() => { 98 | console.log( 99 | 'No internet connection found. App is running in offline mode.' 100 | ); 101 | }); 102 | } 103 | 104 | export function unregister() { 105 | if ('serviceWorker' in navigator) { 106 | navigator.serviceWorker.ready.then(registration => { 107 | registration.unregister(); 108 | }); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /web/app/src/setupTests.ts: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /web/app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "module": "esnext", 16 | "moduleResolution": "node", 17 | "resolveJsonModule": true, 18 | "isolatedModules": true, 19 | "noEmit": true, 20 | "jsx": "react-jsx", 21 | "noFallthroughCasesInSwitch": true 22 | }, 23 | "include": [ 24 | "src" 25 | ] 26 | } 27 | --------------------------------------------------------------------------------