xonecas.io
4515
Nr

node-react-typescript-boilerplate / commit 0f16045

Adds react router and starts on the configuration

Sean2023-01-10 0f16045b1c65be8fb150e1111e39b77ecb1e66f3 parent 3e9255a

37 files changed

client/build/asset-manifest.json+12−12
@@ -1,15 +1,15 @@
11 {
2- "main.css": "/static/css/main.c8758b99.chunk.css",
3- "main.js": "/static/js/main.e9384b50.chunk.js",
4- "main.js.map": "/static/js/main.e9384b50.chunk.js.map",
5- "runtime~main.js": "/static/js/runtime~main.a084bf6b.js",
6- "runtime~main.js.map": "/static/js/runtime~main.a084bf6b.js.map",
7- "static/js/2.879bba26.chunk.js": "/static/js/2.879bba26.chunk.js",
8- "static/js/2.879bba26.chunk.js.map": "/static/js/2.879bba26.chunk.js.map",
9- "static/js/3.5042479d.chunk.js": "/static/js/3.5042479d.chunk.js",
10- "static/js/3.5042479d.chunk.js.map": "/static/js/3.5042479d.chunk.js.map",
2+ "main.css": "/static/css/main.879deb1c.chunk.css",
3+ "main.js": "/static/js/main.1b87a230.chunk.js",
4+ "main.js.map": "/static/js/main.1b87a230.chunk.js.map",
5+ "static/js/1.f4a2a6c0.chunk.js": "/static/js/1.f4a2a6c0.chunk.js",
6+ "static/js/1.f4a2a6c0.chunk.js.map": "/static/js/1.f4a2a6c0.chunk.js.map",
7+ "static/js/2.b0fd3b70.chunk.js": "/static/js/2.b0fd3b70.chunk.js",
8+ "static/js/2.b0fd3b70.chunk.js.map": "/static/js/2.b0fd3b70.chunk.js.map",
9+ "runtime~main.js": "/static/js/runtime~main.6f2903f8.js",
10+ "runtime~main.js.map": "/static/js/runtime~main.6f2903f8.js.map",
11+ "static/css/main.879deb1c.chunk.css.map": "/static/css/main.879deb1c.chunk.css.map",
1112 "index.html": "/index.html",
12- "precache-manifest.8a877dd3f9a99ffb1afdaacef9a3a20f.js": "/precache-manifest.8a877dd3f9a99ffb1afdaacef9a3a20f.js",
13- "service-worker.js": "/service-worker.js",
14- "static/css/main.c8758b99.chunk.css.map": "/static/css/main.c8758b99.chunk.css.map"
13+ "precache-manifest.12854982b722a6a03da677b9f7e3e6fc.js": "/precache-manifest.12854982b722a6a03da677b9f7e3e6fc.js",
14+ "service-worker.js": "/service-worker.js"
1515 }
client/build/index.html+1−1
@@ -1 +1 @@
1-<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><link href="/static/css/main.c8758b99.chunk.css" rel="stylesheet"></head><body><noscript>You nee …
1+<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>App</title><link href="/static/css/main.879deb1c.chunk.css" rel="stylesheet"></head><body><noscript>You need to e …
client/build/precache-manifest.12854982b722a6a03da677b9f7e3e6fc.js+26−0
@@ -0,0 +1,26 @@
1+self.__precacheManifest = [
2+ {
3+ "revision": "1b87a2302fc35514540f",
4+ "url": "/static/css/main.879deb1c.chunk.css"
5+ },
6+ {
7+ "revision": "1b87a2302fc35514540f",
8+ "url": "/static/js/main.1b87a230.chunk.js"
9+ },
10+ {
11+ "revision": "f4a2a6c05474266edc2e",
12+ "url": "/static/js/1.f4a2a6c0.chunk.js"
13+ },
14+ {
15+ "revision": "b0fd3b70842db416d825",
16+ "url": "/static/js/2.b0fd3b70.chunk.js"
17+ },
18+ {
19+ "revision": "6f2903f8d453d711a5fa",
20+ "url": "/static/js/runtime~main.6f2903f8.js"
21+ },
22+ {
23+ "revision": "77d28eec03f2c279094655e905d8b5bf",
24+ "url": "/index.html"
25+ }
26+];
client/build/precache-manifest.8a877dd3f9a99ffb1afdaacef9a3a20f.js+0−26
@@ -1,26 +0,0 @@
1-self.__precacheManifest = [
2- {
3- "revision": "ed4dba4df6189caf6a8d",
4- "url": "/static/css/main.c8758b99.chunk.css"
5- },
6- {
7- "revision": "ed4dba4df6189caf6a8d",
8- "url": "/static/js/main.e9384b50.chunk.js"
9- },
10- {
11- "revision": "13810285cfe83a0e3f7c",
12- "url": "/static/js/runtime~main.a084bf6b.js"
13- },
14- {
15- "revision": "7035108e780caa696b6e",
16- "url": "/static/js/2.879bba26.chunk.js"
17- },
18- {
19- "revision": "19ddbbd90272197c9edd",
20- "url": "/static/js/3.5042479d.chunk.js"
21- },
22- {
23- "revision": "7b6dc1c13a2cb224985413c7da4d5da6",
24- "url": "/index.html"
25- }
26-];
client/build/service-worker.js+1−1
@@ -14,7 +14,7 @@
1414 importScripts("https://storage.googleapis.com/workbox-cdn/releases/3.6.3/workbox-sw.js");
1515
1616 importScripts(
17- "/precache-manifest.8a877dd3f9a99ffb1afdaacef9a3a20f.js"
17+ "/precache-manifest.12854982b722a6a03da677b9f7e3e6fc.js"
1818 );
1919
2020 workbox.clientsClaim();
client/build/static/css/main.879deb1c.chunk.css+1−1
@@ -1,2 +1,2 @@
11 body{margin:0;font-family:Helvetica Neue,sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}code{font-family:Consolas,Courier New,monospace}
2-/*# sourceMappingURL=main.c8758b99.chunk.css.map */
2+/*# sourceMappingURL=main.879deb1c.chunk.css.map */
client/build/static/css/main.879deb1c.chunk.css.map+1−1
@@ -1 +1 @@
1-{"version":3,"sources":["/home/sean/src/koa_react_ts/client/src/index.css","main.c8758b99.chunk.css"],"names":[],"mappings":"AAAA,KACE,QAAA,CACA,qCAAA,CACA,kCAAA,CACA,iCCCF,CDEA,KACE,0CCCF","file":"main.c8758b99.chunk.css","sourcesContent":["body {\n margin: 0;\n font-family: 'Helvetica Neue', sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n font-family: Consolas, 'Courier New', monospace;\n}","body {\n margin: 0;\n font-family: 'Helv …
1+{"version":3,"sources":["/home/sean/src/koa_react_ts/client/src/index.css","main.879deb1c.chunk.css"],"names":[],"mappings":"AAAA,KACE,QAAA,CACA,qCAAA,CACA,kCAAA,CACA,iCCCF,CDEA,KACE,0CCCF","file":"main.879deb1c.chunk.css","sourcesContent":["body {\n margin: 0;\n font-family: 'Helvetica Neue', sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n font-family: Consolas, 'Courier New', monospace;\n}","body {\n margin: 0;\n font-family: 'Helv …
client/build/static/js/1.f4a2a6c0.chunk.js+2−2
@@ -1,2 +1,2 @@
1-(window.webpackJsonp=window.webpackJsonp||[]).push([[3],{40:function(e,n,t){"use strict";t.r(n),t.d(n,"getCLS",function(){return y}),t.d(n,"getFCP",function(){return g}),t.d(n,"getFID",function(){return C}),t.d(n,"getLCP",function(){return k}),t.d(n,"getTTFB",function(){return D});var i,r,a,o,u=function(e,n){return{name:e,value:void 0===n?-1:n,delta:0,entries:[],id:"v2-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12)}},c=function(e,n){try{if(PerformanceObserver.suppo …
2-//# sourceMappingURL=3.5042479d.chunk.js.map
1+(window.webpackJsonp=window.webpackJsonp||[]).push([[1],{52:function(e,n,t){"use strict";t.r(n),t.d(n,"getCLS",function(){return y}),t.d(n,"getFCP",function(){return g}),t.d(n,"getFID",function(){return C}),t.d(n,"getLCP",function(){return k}),t.d(n,"getTTFB",function(){return D});var i,r,a,o,u=function(e,n){return{name:e,value:void 0===n?-1:n,delta:0,entries:[],id:"v2-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12)}},c=function(e,n){try{if(PerformanceObserver.suppo …
2+//# sourceMappingURL=1.f4a2a6c0.chunk.js.map
client/build/static/js/1.f4a2a6c0.chunk.js.map+1−1
@@ -1 +1 @@
1-{"version":3,"sources":["../node_modules/web-vitals/dist/web-vitals.js"],"names":["__webpack_require__","r","__webpack_exports__","d","h","L","F","P","e","t","n","i","name","value","delta","entries","id","concat","Date","now","Math","floor","random","a","PerformanceObserver","supportedEntryTypes","includes","self","getEntries","map","observe","type","buffered","o","document","visibilityState","removeEventListener","addEventListener","u","persisted","c","f","s","m","timeStamp","v","setTimeout","f …
1+{"version":3,"sources":["../node_modules/web-vitals/dist/web-vitals.js"],"names":["__webpack_require__","r","__webpack_exports__","d","h","L","F","P","e","t","n","i","name","value","delta","entries","id","concat","Date","now","Math","floor","random","a","PerformanceObserver","supportedEntryTypes","includes","self","getEntries","map","observe","type","buffered","o","document","visibilityState","removeEventListener","addEventListener","u","persisted","c","f","s","m","timeStamp","v","setTimeout","f …
client/build/static/js/2.879bba26.chunk.js+0−2
@@ -1,2 +0,0 @@
1-(window.webpackJsonp=window.webpackJsonp||[]).push([[2],[function(e,t,n){"use strict";(function(e){var r,a=n(9),o=Object.prototype.toString,i=Object.getPrototypeOf,l=(r=Object.create(null),function(e){var t=o.call(e);return r[t]||(r[t]=t.slice(8,-1).toLowerCase())}),u=function(e){return e=e.toLowerCase(),function(t){return l(t)===e}},s=function(e){return function(t){return typeof t===e}},c=Array.isArray,f=s("undefined");var d=u("ArrayBuffer");var p=s("string"),h=s("function"),m=s("number"),g=fun …
2-//# sourceMappingURL=2.879bba26.chunk.js.map
client/build/static/js/2.879bba26.chunk.js.map+0−1
@@ -1 +0,0 @@
1-{"version":3,"sources":["../node_modules/axios/lib/utils.js","../node_modules/react/index.js","../node_modules/axios/lib/core/AxiosError.js","../node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/esm/slicedToArray.js","../node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/esm/arrayWithHoles.js","../node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/esm/iterableToArrayLimit.js","../node_modules/babel-preset-react-app/node_modules/@bab …
client/build/static/js/2.b0fd3b70.chunk.js+2−0
@@ -0,0 +1,2 @@
1+(window.webpackJsonp=window.webpackJsonp||[]).push([[2],[function(e,t,n){"use strict";n.d(t,"a",function(){return W}),n.d(t,"b",function(){return H}),n.d(t,"c",function(){return k}),n.d(t,"d",function(){return S}),n.d(t,"e",function(){return x}),n.d(t,"f",function(){return O}),n.d(t,"g",function(){return Q}),n.d(t,"h",function(){return P}),n.d(t,"i",function(){return A}),n.d(t,"j",function(){return $}),n.d(t,"k",function(){return T}),n.d(t,"l",function(){return B}),n.d(t,"m",function(){return j} …
2+//# sourceMappingURL=2.b0fd3b70.chunk.js.map
client/build/static/js/2.b0fd3b70.chunk.js.map+1−0
@@ -0,0 +1 @@
1+{"version":3,"sources":["../node_modules/react-router/dist/index.js","../node_modules/react/index.js","../node_modules/axios/lib/utils.js","../node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js","../node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/esm/defineProperty.js","../node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/esm/construct.js","../node_modules/babel-preset-react-app/node_modules/@babel/runtime …
client/build/static/js/main.1b87a230.chunk.js+2−0
@@ -0,0 +1,2 @@
1+(window.webpackJsonp=window.webpackJsonp||[]).push([[0],{33:function(e,n,t){e.exports=t(50)},48:function(e,n,t){},50:function(e,n,t){"use strict";t.r(n);var a,l,r,o,c,i=t(1),u=t.n(i),m=t(26),d=t.n(m),s=t(32),p=t(0),g=t(12),f=t(4),b=t(53),E=t(13);function h(e){var n=e.initialMode,t=Object(i.useState)(n),a=Object(f.a)(t,2),l=a[0],r=a[1],o=Object(i.useState)(""),c=Object(f.a)(o,2),m=c[0],d=c[1],s=Object(i.useState)(""),p=Object(f.a)(s,2),g=p[0],E=p[1],h=Object(i.useState)(""),x=Object(f.a)(h,2),y=x …
2+//# sourceMappingURL=main.1b87a230.chunk.js.map
client/build/static/js/main.1b87a230.chunk.js.map+1−0
@@ -0,0 +1 @@
1+{"version":3,"sources":["components/login/index.tsx","reportWebVitals.ts","index.tsx"],"names":["LoginForm","_ref","initialMode","_useState","useState","_useState2","Object","slicedToArray","mode","setMode","_useState3","_useState4","email","setEmail","_useState5","_useState6","name","setName","_useState7","_useState8","password","setPassword","handleSubmit","e","preventDefault","axios","post","concat","headers","Content-Type","then","response","console","log","catch","error","react_default","a" …
client/build/static/js/main.e9384b50.chunk.js+0−2
@@ -1,2 +0,0 @@
1-(window.webpackJsonp=window.webpackJsonp||[]).push([[0],{21:function(e,n,t){e.exports=t(37)},29:function(e,n,t){},37:function(e,n,t){"use strict";t.r(n);var a,l,r,o,c,i=t(1),u=t.n(i),m=t(14),d=t.n(m),s=(t(29),t(5)),p=t(15),g=t.n(p),f=t(6),b=t(3),E=t(39);function h(e){var n=e.initialMode,t=Object(i.useState)(n),a=Object(b.a)(t,2),l=a[0],r=a[1],o=Object(i.useState)(""),c=Object(b.a)(o,2),m=c[0],d=c[1],s=Object(i.useState)(""),p=Object(b.a)(s,2),g=p[0],f=p[1],h=Object(i.useState)(""),j=Object(b.a)( …
2-//# sourceMappingURL=main.e9384b50.chunk.js.map
client/build/static/js/main.e9384b50.chunk.js.map+0−1
@@ -1 +0,0 @@
1-{"version":3,"sources":["components/login/index.tsx","App.tsx","reportWebVitals.ts","index.tsx"],"names":["LoginForm","_ref","initialMode","_useState","useState","_useState2","Object","slicedToArray","mode","setMode","_useState3","_useState4","email","setEmail","_useState5","_useState6","name","setName","_useState7","_useState8","password","setPassword","handleSubmit","e","preventDefault","axios","post","concat","headers","Content-Type","then","response","console","log","catch","error","react_de …
client/build/static/js/runtime~main.6f2903f8.js+2−0
@@ -0,0 +1,2 @@
1+!function(e){function t(t){for(var n,i,a=t[0],c=t[1],l=t[2],p=0,s=[];p<a.length;p++)i=a[p],o[i]&&s.push(o[i][0]),o[i]=0;for(n in c)Object.prototype.hasOwnProperty.call(c,n)&&(e[n]=c[n]);for(f&&f(t);s.length;)s.shift()();return u.push.apply(u,l||[]),r()}function r(){for(var e,t=0;t<u.length;t++){for(var r=u[t],n=!0,a=1;a<r.length;a++){var c=r[a];0!==o[c]&&(n=!1)}n&&(u.splice(t--,1),e=i(i.s=r[0]))}return e}var n={},o={3:0},u=[];function i(t){if(n[t])return n[t].exports;var r=n[t]={i:t,l:!1,exports …
2+//# sourceMappingURL=runtime~main.6f2903f8.js.map
client/build/static/js/runtime~main.6f2903f8.js.map+1−0
@@ -0,0 +1 @@
1+{"version":3,"sources":["../webpack/bootstrap"],"names":["webpackJsonpCallback","data","moduleId","chunkId","chunkIds","moreModules","executeModules","i","resolves","length","installedChunks","push","Object","prototype","hasOwnProperty","call","modules","parentJsonpFunction","shift","deferredModules","apply","checkDeferredModules","result","deferredModule","fulfilled","j","depId","splice","__webpack_require__","s","installedModules","3","exports","module","l","e","promises","installedChunkData", …
client/build/static/js/runtime~main.a084bf6b.js+0−2
@@ -1,2 +0,0 @@
1-!function(e){function r(r){for(var n,i,a=r[0],c=r[1],l=r[2],p=0,s=[];p<a.length;p++)i=a[p],o[i]&&s.push(o[i][0]),o[i]=0;for(n in c)Object.prototype.hasOwnProperty.call(c,n)&&(e[n]=c[n]);for(f&&f(r);s.length;)s.shift()();return u.push.apply(u,l||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,a=1;a<t.length;a++){var c=t[a];0!==o[c]&&(n=!1)}n&&(u.splice(r--,1),e=i(i.s=t[0]))}return e}var n={},o={1:0},u=[];function i(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports …
2-//# sourceMappingURL=runtime~main.a084bf6b.js.map
client/build/static/js/runtime~main.a084bf6b.js.map+0−1
@@ -1 +0,0 @@
1-{"version":3,"sources":["../webpack/bootstrap"],"names":["webpackJsonpCallback","data","moduleId","chunkId","chunkIds","moreModules","executeModules","i","resolves","length","installedChunks","push","Object","prototype","hasOwnProperty","call","modules","parentJsonpFunction","shift","deferredModules","apply","checkDeferredModules","result","deferredModule","fulfilled","j","depId","splice","__webpack_require__","s","installedModules","1","exports","module","l","e","promises","installedChunkData", …
client/package-lock.json+39−0
@@ -21,6 +21,7 @@
2121 "js-cookie": "^3.0.1",
2222 "react": "^18.2.0",
2323 "react-dom": "^18.2.0",
24+ "react-router-dom": "6.6.2",
2425 "react-scripts": "^2.1.3",
2526 "styled-components": "^5.3.6",
2627 "typescript": "^4.9.4",
@@ -1903,6 +1904,14 @@
19031904 "node": ">= 6"
19041905 }
19051906 },
1907+ "node_modules/@remix-run/router": {
1908+ "version": "1.2.1",
1909+ "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.2.1.tgz",
1910+ "integrity": "sha512-XiY0IsyHR+DXYS5vBxpoBe/8veTeoRpMHP+vDosLZxL5bnpetzI0igkxkLZS235ldLzyfkxF+2divEwWHP3vMQ==",
1911+ "engines": {
1912+ "node": ">=14"
1913+ }
1914+ },
19061915 "node_modules/@svgr/core": {
19071916 "version": "2.4.1",
19081917 "resolved": "https://registry.npmjs.org/@svgr/core/-/core-2.4.1.tgz",
@@ -15467,6 +15476,36 @@
1546715476 "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
1546815477 "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w=="
1546915478 },
15479+ "node_modules/react-router": {
15480+ "version": "6.6.2",
15481+ "resolved": "https://registry.npmjs.org/react-router/-/react-router-6.6.2.tgz",
15482+ "integrity": "sha512-uJPG55Pek3orClbURDvfljhqFvMgJRo59Pktywkk8hUUkTY2aRfza8Yhl/vZQXs+TNQyr6tu+uqz/fLxPICOGQ==",
15483+ "dependencies": {
15484+ "@remix-run/router": "1.2.1"
15485+ },
15486+ "engines": {
15487+ "node": ">=14"
15488+ },
15489+ "peerDependencies": {
15490+ "react": ">=16.8"
15491+ }
15492+ },
15493+ "node_modules/react-router-dom": {
15494+ "version": "6.6.2",
15495+ "resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-6.6.2.tgz",
15496+ "integrity": "sha512-6SCDXxRQqW5af8ImOqKza7icmQ47/EMbz572uFjzvcArg3lZ+04PxSPp8qGs+p2Y+q+b+S/AjXv8m8dyLndIIA==",
15497+ "dependencies": {
15498+ "@remix-run/router": "1.2.1",
15499+ "react-router": "6.6.2"
15500+ },
15501+ "engines": {
15502+ "node": ">=14"
15503+ },
15504+ "peerDependencies": {
15505+ "react": ">=16.8",
15506+ "react-dom": ">=16.8"
15507+ }
15508+ },
1547015509 "node_modules/react-scripts": {
1547115510 "version": "2.1.3",
1547215511 "resolved": "https://registry.npmjs.org/react-scripts/-/react-scripts-2.1.3.tgz",
client/package.json+2−1
@@ -2,7 +2,7 @@
22 "name": "client",
33 "version": "0.1.0",
44 "private": true,
5- "homepage": "http://localhost:3001/",
5+ "homepage": "/",
66 "dependencies": {
77 "@testing-library/jest-dom": "^5.16.5",
88 "@testing-library/react": "^13.4.0",
@@ -18,6 +18,7 @@
1818 "react": "^18.2.0",
1919 "react-dom": "^18.2.0",
2020 "react-scripts": "^2.1.3",
21+ "react-router-dom": "6.6.2",
2122 "styled-components": "^5.3.6",
2223 "typescript": "^4.9.4",
2324 "web-vitals": "^2.1.4"
client/public/index.html+1−1
@@ -24,7 +24,7 @@
2424 work correctly both with client-side routing and a non-root public URL.
2525 Learn how to configure a non-root public URL by running `npm run build`.
2626 -->
27- <title>React App</title>
27+ <title>App</title>
2828 </head>
2929 <body>
3030 <noscript>You need to enable JavaScript to run this app.</noscript>
client/src/App.test.tsx+0−9
@@ -1,9 +0,0 @@
1-import React from 'react';
2-import { render, screen } from '@testing-library/react';
3-import App from './App';
4-
5-test('renders learn react link', () => {
6- render(<App />);
7- const linkElement = screen.getByText(/Email/i);
8- expect(linkElement).toBeInTheDocument();
9-});
client/src/App.tsx+0−22
@@ -1,22 +0,0 @@
1-// import './App.css';
2-import React from "react";
3-import Cookies from "js-cookie";
4-import styled from "styled-components";
5-import LoginForm from "./components/login";
6-
7-function App() {
8- const isLoggedIn = Cookies.get("logged_user");
9-
10- return (
11- <PageContainer>
12- {isLoggedIn ? <>Your app here</> : <LoginForm initialMode="login" />}
13- </PageContainer>
14- );
15-}
16-
17-const PageContainer = styled.div`
18- display: flex;
19- justify-content: center;
20-`;
21-
22-export default App;
client/src/components/login/index.tsx+10−18
@@ -18,19 +18,11 @@ export default function LoginForm({
1818 e.preventDefault();
1919
2020 axios
21- .post(
22- `/auth/${mode}`,
23- {
24- email,
25- name,
26- password,
27- },
28- {
29- headers: {
30- "Content-Type": "application/json",
31- },
32- }
33- )
21+ .post(`/auth/${mode}`, {
22+ email,
23+ name,
24+ password,
25+ })
3426 .then((response) => {
3527 console.log(response);
3628 // Redirect the user back
@@ -111,14 +103,14 @@ const StyledLoginForm = styled.form`
111103 width: 300px;
112104
113105 p {
114- margin: 0 0 .5em 0;
106+ margin: 0 0 0.5em 0;
115107 padding: 0;
116108 }
117109 `;
118110
119111 const StyledLoginFromInputs = styled.input`
120- font-family: Consolas, 'Courier New', monospace;
121- padding: .25em .25em .3em;
112+ font-family: Consolas, "Courier New", monospace;
113+ padding: 0.25em 0.25em 0.3em;
122114 margin: 0 0 1em 0;
123115 border: 1px solid #ddd;
124116 border-radius: 4px;
@@ -133,7 +125,7 @@ const StyledSmallText = styled.h3`
133125 color: #aaa;
134126 font-size: 12px;
135127 font-weight: 400;
136- padding: .5em 0 1em;
128+ padding: 0.5em 0 1em;
137129 `;
138130
139131 const StyledButtonContainer = styled.div`
@@ -143,7 +135,7 @@ const StyledButtonContainer = styled.div`
143135
144136 const StyledButton = styled.button`
145137 margin: 1em 0 0 0;
146- padding: .25em .5em;
138+ padding: 0.25em 0.5em;
147139 border: 1px solid #ddd;
148140 border-radius: 4px;
149141 background-color: #111;
client/src/components/page-container/index.tsx+9−0
@@ -0,0 +1,9 @@
1+import React from "react";
2+import styled from "styled-components"
3+
4+const PageContainer = styled.div`
5+ display: flex;
6+ justify-content: center;
7+`;
8+
9+export default PageContainer
client/src/index.tsx+41−7
@@ -1,15 +1,49 @@
1-import React from 'react';
2-import ReactDOM from 'react-dom/client';
3-import './index.css';
4-import App from './App';
5-import reportWebVitals from './reportWebVitals';
1+import React from "react";
2+import ReactDOM from "react-dom/client";
3+import { RouterProvider, createBrowserRouter } from "react-router-dom";
4+import LoginForm from "./components/login";
5+import PageContainer from "./components/page-container";
6+import "./index.css";
7+import reportWebVitals from "./reportWebVitals";
8+import axios from "axios";
9+
10+//@TODO api url
11+axios.defaults.baseURL = "http://localhost:3001";
12+axios.defaults.headers["Content-Type"] = "application/json";
13+
14+const router = createBrowserRouter([
15+ {
16+ path: "/",
17+ element: (
18+ <PageContainer>
19+ <h1>Home</h1>
20+ </PageContainer>
21+ ),
22+ },
23+ {
24+ path: "/login",
25+ element: (
26+ <PageContainer>
27+ <LoginForm initialMode="login" />
28+ </PageContainer>
29+ ),
30+ },
31+ {
32+ path: "/register",
33+ element: (
34+ <PageContainer>
35+ <LoginForm initialMode="register" />
36+ </PageContainer>
37+ ),
38+ },
39+]);
640
741 const root = ReactDOM.createRoot(
8- document.getElementById('root') as HTMLElement
42+ document.getElementById("root") as HTMLElement
943 );
1044 root.render(
1145 <React.StrictMode>
12- <App />
46+ <RouterProvider router={router} />
1347 </React.StrictMode>
1448 );
1549
dist/auth/index.js+2−3
@@ -10,13 +10,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
1010 };
1111 Object.defineProperty(exports, "__esModule", { value: true });
1212 exports.login = exports.register = void 0;
13-const index_1 = require("../index");
1413 const client_1 = require("@prisma/client");
1514 function register(ctx, next) {
1615 return __awaiter(this, void 0, void 0, function* () {
1716 try {
1817 const data = ctx.request.body;
19- const user = yield index_1.prisma.user.create({
18+ const user = yield ctx.prisma.user.create({
2019 data: data,
2120 });
2221 ctx.cookies.set("logged_user", user.email, { httpOnly: false });
@@ -44,7 +43,7 @@ exports.register = register;
4443 function login(ctx, next) {
4544 return __awaiter(this, void 0, void 0, function* () {
4645 const data = ctx.request.body;
47- const user = yield index_1.prisma.user.findUnique({ where: { email: data.email } });
46+ const user = yield ctx.prisma.user.findUnique({ where: { email: data.email } });
4847 if (!user) {
4948 ctx.status = 400;
5049 ctx.response.body = { error: "No user with specified email." };
dist/auth/routes.js+11−0
@@ -0,0 +1,11 @@
1+"use strict";
2+var __importDefault = (this && this.__importDefault) || function (mod) {
3+ return (mod && mod.__esModule) ? mod : { "default": mod };
4+};
5+Object.defineProperty(exports, "__esModule", { value: true });
6+const koa_router_1 = __importDefault(require("koa-router"));
7+const _1 = require(".");
8+const router = new koa_router_1.default();
9+router.post("/register", _1.register);
10+router.post("/login", _1.login);
11+exports.default = router;
dist/index.js+13−14
@@ -12,32 +12,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
1212 return (mod && mod.__esModule) ? mod : { "default": mod };
1313 };
1414 Object.defineProperty(exports, "__esModule", { value: true });
15-exports.prisma = void 0;
15+const cors_1 = __importDefault(require("@koa/cors"));
1616 const client_1 = require("@prisma/client");
1717 const koa_1 = __importDefault(require("koa"));
18-const koa_json_1 = __importDefault(require("koa-json"));
1918 const koa_body_1 = __importDefault(require("koa-body"));
19+const koa_json_1 = __importDefault(require("koa-json"));
2020 const koa_logger_1 = __importDefault(require("koa-logger"));
2121 const koa_router_1 = __importDefault(require("koa-router"));
22-const koa_static_1 = __importDefault(require("koa-static"));
2322 const strip_ansi_1 = __importDefault(require("strip-ansi"));
24-const auth_1 = require("./auth");
2523 // try got and axios for server to server requests
26-// Export the client to let prisma manage the connection pool
27-exports.prisma = new client_1.PrismaClient();
24+// Create the client to let prisma manage the connection pool
25+const prisma = new client_1.PrismaClient();
2826 function main() {
2927 return __awaiter(this, void 0, void 0, function* () {
3028 const app = new koa_1.default();
3129 const router = new koa_router_1.default();
3230 // Middleware:
3331 app.use((0, koa_logger_1.default)((str) => {
34- // Remove colors since they clash with my terminal
32+ // Remove colors for simplicity.
3533 console.log((0, strip_ansi_1.default)(str));
3634 }));
3735 app.use((0, koa_json_1.default)());
3836 app.use((0, koa_body_1.default)());
39- // Serve built react app
40- app.use((0, koa_static_1.default)("client/build"));
37+ app.use((0, cors_1.default)());
38+ // Share the connection for the db:
39+ app.use((ctx) => __awaiter(this, void 0, void 0, function* () {
40+ ctx.prisma = prisma;
41+ }));
4142 // health-check:
4243 router.get("/health-check", (ctx, next) => __awaiter(this, void 0, void 0, function* () {
4344 ctx.response.body = {
@@ -46,11 +47,9 @@ function main() {
4647 ctx.response.status = 200;
4748 yield next();
4849 }));
49- // Auth:
50- router.post("/auth/register", auth_1.register);
51- router.post("/auth/login", auth_1.login);
5250 // Serve configured routes:
5351 app.use(router.routes()).use(router.allowedMethods());
52+ // app.use(auth_router.routes()).use(auth_router.allowedMethods());
5453 // App starts
5554 app.listen(3001, () => {
5655 console.log("Server started...");
@@ -59,10 +58,10 @@ function main() {
5958 }
6059 main()
6160 .then(() => __awaiter(void 0, void 0, void 0, function* () {
62- yield exports.prisma.$disconnect();
61+ yield prisma.$disconnect();
6362 }))
6463 .catch((e) => __awaiter(void 0, void 0, void 0, function* () {
6564 console.error(e);
66- yield exports.prisma.$disconnect();
65+ yield prisma.$disconnect();
6766 process.exit();
6867 }));
package-lock.json+22−104
@@ -5,19 +5,19 @@
55 "packages": {
66 "": {
77 "dependencies": {
8+ "@koa/cors": "^4.0.0",
89 "@prisma/client": "^4.8.1",
9- "@types/koa-static": "^4.0.2",
1010 "koa": "^2.14.1",
1111 "koa-body": "^6.0.1",
1212 "koa-json": "^2.0.2",
1313 "koa-logger": "^3.2.1",
1414 "koa-router": "^12.0.0",
15- "koa-static": "^5.0.0",
1615 "prisma": "^4.8.1",
1716 "strip-ansi": "6.0.0"
1817 },
1918 "devDependencies": {
2019 "@types/koa": "^2.13.5",
20+ "@types/koa__cors": "^3.3.0",
2121 "@types/koa-json": "^2.0.20",
2222 "@types/koa-logger": "^3.1.2",
2323 "@types/koa-router": "^7.4.4",
@@ -27,6 +27,17 @@
2727 "typescript": "^4.9.4"
2828 }
2929 },
30+ "node_modules/@koa/cors": {
31+ "version": "4.0.0",
32+ "resolved": "https://registry.npmjs.org/@koa/cors/-/cors-4.0.0.tgz",
33+ "integrity": "sha512-Y4RrbvGTlAaa04DBoPBWJqDR5gPj32OOz827ULXfgB1F7piD1MB/zwn8JR2LAnvdILhxUbXbkXGWuNVsFuVFCQ==",
34+ "dependencies": {
35+ "vary": "^1.1.2"
36+ },
37+ "engines": {
38+ "node": ">= 14.0.0"
39+ }
40+ },
3041 "node_modules/@prisma/client": {
3142 "version": "4.8.1",
3243 "resolved": "https://registry.npmjs.org/@prisma/client/-/client-4.8.1.tgz",
@@ -167,6 +178,15 @@
167178 "@types/node": "*"
168179 }
169180 },
181+ "node_modules/@types/koa__cors": {
182+ "version": "3.3.0",
183+ "resolved": "https://registry.npmjs.org/@types/koa__cors/-/koa__cors-3.3.0.tgz",
184+ "integrity": "sha512-FUN8YxcBakIs+walVe3+HcNP+Bxd0SB8BJHBWkglZ5C1XQWljlKcEFDG/dPiCIqwVCUbc5X0nYDlH62uEhdHMA==",
185+ "dev": true,
186+ "dependencies": {
187+ "@types/koa": "*"
188+ }
189+ },
170190 "node_modules/@types/koa-compose": {
171191 "version": "3.2.5",
172192 "resolved": "https://registry.npmjs.org/@types/koa-compose/-/koa-compose-3.2.5.tgz",
@@ -202,23 +222,6 @@
202222 "@types/koa": "*"
203223 }
204224 },
205- "node_modules/@types/koa-send": {
206- "version": "4.1.3",
207- "resolved": "https://registry.npmjs.org/@types/koa-send/-/koa-send-4.1.3.tgz",
208- "integrity": "sha512-daaTqPZlgjIJycSTNjKpHYuKhXYP30atFc1pBcy6HHqB9+vcymDgYTguPdx9tO4HMOqNyz6bz/zqpxt5eLR+VA==",
209- "dependencies": {
210- "@types/koa": "*"
211- }
212- },
213- "node_modules/@types/koa-static": {
214- "version": "4.0.2",
215- "resolved": "https://registry.npmjs.org/@types/koa-static/-/koa-static-4.0.2.tgz",
216- "integrity": "sha512-ns/zHg+K6XVPMuohjpOlpkR1WLa4VJ9czgUP9bxkCDn0JZBtUWbD/wKDZzPGDclkQK1bpAEScufCHOy8cbfL0w==",
217- "dependencies": {
218- "@types/koa": "*",
219- "@types/koa-send": "*"
220- }
221- },
222225 "node_modules/@types/mime": {
223226 "version": "3.0.1",
224227 "resolved": "https://registry.npmjs.org/@types/mime/-/mime-3.0.1.tgz",
@@ -980,39 +983,6 @@
980983 "node": ">= 0.8"
981984 }
982985 },
983- "node_modules/koa-send": {
984- "version": "5.0.1",
985- "resolved": "https://registry.npmjs.org/koa-send/-/koa-send-5.0.1.tgz",
986- "integrity": "sha512-tmcyQ/wXXuxpDxyNXv5yNNkdAMdFRqwtegBXUaowiQzUKqJehttS0x2j0eOZDQAyloAth5w6wwBImnFzkUz3pQ==",
987- "dependencies": {
988- "debug": "^4.1.1",
989- "http-errors": "^1.7.3",
990- "resolve-path": "^1.4.0"
991- },
992- "engines": {
993- "node": ">= 8"
994- }
995- },
996- "node_modules/koa-static": {
997- "version": "5.0.0",
998- "resolved": "https://registry.npmjs.org/koa-static/-/koa-static-5.0.0.tgz",
999- "integrity": "sha512-UqyYyH5YEXaJrf9S8E23GoJFQZXkBVJ9zYYMPGz919MSX1KuvAcycIuS0ci150HCoPf4XQVhQ84Qf8xRPWxFaQ==",
1000- "dependencies": {
1001- "debug": "^3.1.0",
1002- "koa-send": "^5.0.0"
1003- },
1004- "engines": {
1005- "node": ">= 7.6.0"
1006- }
1007- },
1008- "node_modules/koa-static/node_modules/debug": {
1009- "version": "3.2.7",
1010- "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz",
1011- "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==",
1012- "dependencies": {
1013- "ms": "^2.1.1"
1014- }
1015- },
1016986 "node_modules/media-typer": {
1017987 "version": "0.3.0",
1018988 "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
@@ -1179,14 +1149,6 @@
11791149 "resolved": "https://registry.npmjs.org/passthrough-counter/-/passthrough-counter-1.0.0.tgz",
11801150 "integrity": "sha512-Wy8PXTLqPAN0oEgBrlnsXPMww3SYJ44tQ8aVrGAI4h4JZYCS0oYqsPqtPR8OhJpv6qFbpbB7XAn0liKV7EXubA=="
11811151 },
1182- "node_modules/path-is-absolute": {
1183- "version": "1.0.1",
1184- "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
1185- "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==",
1186- "engines": {
1187- "node": ">=0.10.0"
1188- }
1189- },
11901152 "node_modules/path-to-regexp": {
11911153 "version": "6.2.1",
11921154 "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.2.1.tgz",
@@ -1313,50 +1275,6 @@
13131275 "node": ">=8.10.0"
13141276 }
13151277 },
1316- "node_modules/resolve-path": {
1317- "version": "1.4.0",
1318- "resolved": "https://registry.npmjs.org/resolve-path/-/resolve-path-1.4.0.tgz",
1319- "integrity": "sha512-i1xevIst/Qa+nA9olDxLWnLk8YZbi8R/7JPbCMcgyWaFR6bKWaexgJgEB5oc2PKMjYdrHynyz0NY+if+H98t1w==",
1320- "dependencies": {
1321- "http-errors": "~1.6.2",
1322- "path-is-absolute": "1.0.1"
1323- },
1324- "engines": {
1325- "node": ">= 0.8"
1326- }
1327- },
1328- "node_modules/resolve-path/node_modules/depd": {
1329- "version": "1.1.2",
1330- "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
1331- "integrity": "sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==",
1332- "engines": {
1333- "node": ">= 0.6"
1334- }
1335- },
1336- "node_modules/resolve-path/node_modules/http-errors": {
1337- "version": "1.6.3",
1338- "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz",
1339- "integrity": "sha512-lks+lVC8dgGyh97jxvxeYTWQFvh4uw4yC12gVl63Cg30sjPX4wuGcdkICVXDAESr6OJGjqGA8Iz5mkeN6zlD7A==",
1340- "dependencies": {
1341- "depd": "~1.1.2",
1342- "inherits": "2.0.3",
1343- "setprototypeof": "1.1.0",
1344- "statuses": ">= 1.4.0 < 2"
1345- },
1346- "engines": {
1347- "node": ">= 0.6"
1348- }
1349- },
1350- "node_modules/resolve-path/node_modules/inherits": {
1351- "version": "2.0.3",
1352- "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
1353- "integrity": "sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw=="
1354- },
1355- "node_modules/resolve-path/node_modules/setprototypeof": {
1356- "version": "1.1.0",
1357- "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz",
1358- "integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ=="
1359- },
13601278 "node_modules/safe-buffer": {
13611279 "version": "5.2.1",
13621280 "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
package.json+2−2
@@ -1,6 +1,7 @@
11 {
22 "devDependencies": {
33 "@types/koa": "^2.13.5",
4+ "@types/koa__cors": "^3.3.0",
45 "@types/koa-json": "^2.0.20",
56 "@types/koa-logger": "^3.1.2",
67 "@types/koa-router": "^7.4.4",
@@ -10,14 +11,13 @@
1011 "typescript": "^4.9.4"
1112 },
1213 "dependencies": {
14+ "@koa/cors": "^4.0.0",
1315 "@prisma/client": "^4.8.1",
14- "@types/koa-static": "^4.0.2",
1516 "koa": "^2.14.1",
1617 "koa-body": "^6.0.1",
1718 "koa-json": "^2.0.2",
1819 "koa-logger": "^3.2.1",
1920 "koa-router": "^12.0.0",
20- "koa-static": "^5.0.0",
2121 "prisma": "^4.8.1",
2222 "strip-ansi": "6.0.0"
2323 }
src/auth/index.ts+2−3
@@ -1,11 +1,10 @@
11 import Koa from "koa";
2-import { prisma } from "../index";
32 import { Prisma } from "@prisma/client";
43
54 export async function register(ctx: Koa.ParameterizedContext, next: Koa.Next) {
65 try {
76 const data = ctx.request.body;
8- const user = await prisma.user.create({
7+ const user = await ctx.prisma.user.create({
98 data: data,
109 });
1110
@@ -31,7 +30,7 @@ export async function register(ctx: Koa.ParameterizedContext, next: Koa.Next) {
3130
3231 export async function login(ctx: Koa.ParameterizedContext, next: Koa.Next) {
3332 const data = ctx.request.body;
34- const user = await prisma.user.findUnique({ where: { email: data.email } });
33+ const user = await ctx.prisma.user.findUnique({ where: { email: data.email } });
3534
3635 if (!user) {
3736 ctx.status = 400;
src/auth/routes.ts+9−0
@@ -0,0 +1,9 @@
1+import Router from "koa-router";
2+import { register, login } from ".";
3+
4+const router = new Router();
5+
6+router.post("/register", register);
7+router.post("/login", login);
8+
9+export default router;
src/index.ts+12−12
@@ -1,16 +1,16 @@
1+import cors from "@koa/cors";
12 import { PrismaClient } from "@prisma/client";
23 import Koa from "koa";
3-import json from "koa-json";
44 import body from "koa-body";
5+import json from "koa-json";
56 import logger from "koa-logger";
67 import Router from "koa-router";
7-import serve from "koa-static";
88 import stripAnsi from "strip-ansi";
9-import { login, register } from "./auth";
9+import auth_router from "./auth/routes";
1010 // try got and axios for server to server requests
1111
12-// Export the client to let prisma manage the connection pool
13-export const prisma = new PrismaClient();
12+// Create the client to let prisma manage the connection pool
13+const prisma = new PrismaClient();
1414
1515 async function main() {
1616 const app = new Koa();
@@ -19,15 +19,18 @@ async function main() {
1919 // Middleware:
2020 app.use(
2121 logger((str) => {
22- // Remove colors since they clash with my terminal
22+ // Remove colors for simplicity.
2323 console.log(stripAnsi(str));
2424 })
2525 );
2626 app.use(json());
2727 app.use(body());
28+ app.use(cors());
2829
29- // Serve built react app
30- app.use(serve("client/build"));
30+ // Share the connection for the db:
31+ app.use(async (ctx) => {
32+ ctx.prisma = prisma;
33+ });
3134
3235 // health-check:
3336 router.get("/health-check", async (ctx, next) => {
@@ -39,12 +42,9 @@ async function main() {
3942 await next();
4043 });
4144
42- // Auth:
43- router.post("/auth/register", register);
44- router.post("/auth/login", login);
45-
4645 // Serve configured routes:
4746 app.use(router.routes()).use(router.allowedMethods());
47+ // app.use(auth_router.routes()).use(auth_router.allowedMethods());
4848
4949 // App starts
5050 app.listen(3001, () => {