From 65ddbe976fb51dcdbb15a0aaea48592328f43c62 Mon Sep 17 00:00:00 2001 From: Clement Date: Sat, 20 Apr 2024 11:14:48 +0200 Subject: [PATCH 01/19] rm default style --- front/src/layouts/Layout.astro | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/front/src/layouts/Layout.astro b/front/src/layouts/Layout.astro index 7b552be..5c9eaae 100644 --- a/front/src/layouts/Layout.astro +++ b/front/src/layouts/Layout.astro @@ -19,33 +19,4 @@ const { title } = Astro.props; - - + \ No newline at end of file -- 2.47.1 From 65d52eb8fadb526d145ec89407bf05b0256fce1b Mon Sep 17 00:00:00 2001 From: Clement Date: Sat, 20 Apr 2024 11:15:12 +0200 Subject: [PATCH 02/19] add pb dependancie --- front/package.json | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/front/package.json b/front/package.json index 97f82dd..81e3fe7 100644 --- a/front/package.json +++ b/front/package.json @@ -2,7 +2,7 @@ "name": "front", "type": "module", "version": "0.0.1", - "private":"true", + "private": "true", "scripts": { "dev": "astro dev", "start": "astro dev", @@ -11,23 +11,25 @@ "astro": "astro" }, "dependencies": { + "@astrojs/node": "^8.2.5", "@astrojs/tailwind": "^5.1.0", "@tailwindcss/typography": "^0.5.12", "astro": "^4.6.3", "lucide-astro": "^0.372.0", + "pocketbase": "^0.21.1", "simple-icons-astro": "^11.12.0", "tailwindcss": "^3.4.3", "typescript": "^5.2.2" }, "devDependencies": { - "@astrojs/check": "^0", - "@types/node": "^20", - "@typescript-eslint/eslint-plugin": "^6", - "@typescript-eslint/parser": "^6", - "@vitest/coverage-v8": "^1", - "eslint": "^8", - "eslint-plugin-astro": "^0.31", - "typescript": "^5", - "vitest": "^1" - } + "@astrojs/check": "^0", + "@types/node": "^20", + "@typescript-eslint/eslint-plugin": "^6", + "@typescript-eslint/parser": "^6", + "@vitest/coverage-v8": "^1", + "eslint": "^8", + "eslint-plugin-astro": "^0.31", + "typescript": "^5", + "vitest": "^1" + } } -- 2.47.1 From 79656cfccdc244eba4f91275681c5b67f8925f47 Mon Sep 17 00:00:00 2001 From: Clement Date: Sat, 20 Apr 2024 11:15:33 +0200 Subject: [PATCH 03/19] fix: site output type --- front/astro.config.mjs | 9 +- front/package-lock.json | 182 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 187 insertions(+), 4 deletions(-) diff --git a/front/astro.config.mjs b/front/astro.config.mjs index 30bdc47..8c09f89 100644 --- a/front/astro.config.mjs +++ b/front/astro.config.mjs @@ -1,4 +1,5 @@ import { defineConfig } from 'astro/config'; +import node from '@astrojs/node'; // https://astro.build/config export default defineConfig({ @@ -13,8 +14,8 @@ export default defineConfig({ port: 3000 }, trailingSlash: 'never', - output: 'static', //'server', - // adapter: node({ - // mode: 'standalone' - // }), + output: 'server', + adapter: node({ + mode: 'standalone' + }), }); diff --git a/front/package-lock.json b/front/package-lock.json index 4fda794..1c86d27 100644 --- a/front/package-lock.json +++ b/front/package-lock.json @@ -8,10 +8,12 @@ "name": "front", "version": "0.0.1", "dependencies": { + "@astrojs/node": "^8.2.5", "@astrojs/tailwind": "^5.1.0", "@tailwindcss/typography": "^0.5.12", "astro": "^4.6.3", "lucide-astro": "^0.372.0", + "pocketbase": "^0.21.1", "simple-icons-astro": "^11.12.0", "tailwindcss": "^3.4.3", "typescript": "^5.2.2" @@ -153,6 +155,18 @@ "vfile": "^6.0.1" } }, + "node_modules/@astrojs/node": { + "version": "8.2.5", + "resolved": "https://registry.npmjs.org/@astrojs/node/-/node-8.2.5.tgz", + "integrity": "sha512-IdVD4dBNyg+ScmCATZ0FM7vNLAHq0TSdiJ3LpR4jcWIUhpN1ps5Jg+9CfzMaLmCCe/SJUZejK5EnzqUJdnGYyg==", + "dependencies": { + "send": "^0.18.0", + "server-destroy": "^1.0.1" + }, + "peerDependencies": { + "astro": "^4.2.0" + } + }, "node_modules/@astrojs/prism": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/@astrojs/prism/-/prism-3.1.0.tgz", @@ -3123,6 +3137,14 @@ "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", "dev": true }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/dequal": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", @@ -3131,6 +3153,15 @@ "node": ">=6" } }, + "node_modules/destroy": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", + "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, "node_modules/detect-libc": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.3.tgz", @@ -3232,6 +3263,11 @@ "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==" }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" + }, "node_modules/electron-to-chromium": { "version": "1.4.745", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.745.tgz", @@ -3252,6 +3288,14 @@ "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.3.0.tgz", "integrity": "sha512-QpLs9D9v9kArv4lfDEgg1X/gN5XLnf/A6l9cs8SPZLRZR3ZkY9+kwIQTxm+fsSej5UMYGE8fdoaZVIBlqG0XTw==" }, + "node_modules/encodeurl": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", + "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/end-of-stream": { "version": "1.4.4", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", @@ -3322,6 +3366,11 @@ "node": ">=6" } }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==" + }, "node_modules/escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", @@ -3708,6 +3757,14 @@ "node": ">=0.10.0" } }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/eventemitter3": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz", @@ -3909,6 +3966,14 @@ "url": "https://github.com/sponsors/rawify" } }, + "node_modules/fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/fs-constants": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", @@ -4312,6 +4377,21 @@ "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz", "integrity": "sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==" }, + "node_modules/http-errors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", + "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==", + "dependencies": { + "depd": "2.0.0", + "inherits": "2.0.4", + "setprototypeof": "1.2.0", + "statuses": "2.0.1", + "toidentifier": "1.0.1" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/human-signals": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-5.0.0.tgz", @@ -6006,6 +6086,17 @@ "node": ">= 6" } }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -6409,6 +6500,11 @@ "pathe": "^1.1.2" } }, + "node_modules/pocketbase": { + "version": "0.21.1", + "resolved": "https://registry.npmjs.org/pocketbase/-/pocketbase-0.21.1.tgz", + "integrity": "sha512-0PvCP4pKtxsV9kwldEGyibEvhwOcx9jSCrz3WN5CgPILJfM0z76f1op9WE8/8UgikDsMdRsc5iBLfKintrJS1g==" + }, "node_modules/postcss": { "version": "8.4.38", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.38.tgz", @@ -6770,6 +6866,14 @@ "integrity": "sha512-kJt5qhMxoszgU/62PLP1CJytzd2NKetjSRnyuj31fDd3Rlcz3fzlFdFLD1SItunPwyqEOkca6GbV612BWfaBag==", "optional": true }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/rc": { "version": "1.2.8", "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", @@ -7578,6 +7682,68 @@ "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, + "node_modules/send": { + "version": "0.18.0", + "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz", + "integrity": "sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==", + "dependencies": { + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "fresh": "0.5.2", + "http-errors": "2.0.0", + "mime": "1.6.0", + "ms": "2.1.3", + "on-finished": "2.4.1", + "range-parser": "~1.2.1", + "statuses": "2.0.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/send/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/send/node_modules/debug/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" + }, + "node_modules/send/node_modules/mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/send/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "node_modules/server-destroy": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/server-destroy/-/server-destroy-1.0.1.tgz", + "integrity": "sha512-rb+9B5YBIEzYcD6x2VKidaa+cqYBJQKnU4oe4E3ANwRRN56yk/ua1YCJT1n21NTS8w6CcOclAKNP3PhdCXKYtQ==" + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" + }, "node_modules/sharp": { "version": "0.32.6", "resolved": "https://registry.npmjs.org/sharp/-/sharp-0.32.6.tgz", @@ -7749,6 +7915,14 @@ "integrity": "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==", "dev": true }, + "node_modules/statuses": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", + "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/std-env": { "version": "3.7.0", "resolved": "https://registry.npmjs.org/std-env/-/std-env-3.7.0.tgz", @@ -8208,6 +8382,14 @@ "node": ">=8.0" } }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "engines": { + "node": ">=0.6" + } + }, "node_modules/trim-lines": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/trim-lines/-/trim-lines-3.0.1.tgz", -- 2.47.1 From a2290c21e16575d5ae56a2311352eecffba34f15 Mon Sep 17 00:00:00 2001 From: Clement Date: Sat, 20 Apr 2024 11:45:17 +0200 Subject: [PATCH 04/19] add astro util --- front/src/libs/AstroUtils.ts | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 front/src/libs/AstroUtils.ts diff --git a/front/src/libs/AstroUtils.ts b/front/src/libs/AstroUtils.ts new file mode 100644 index 0000000..c97a8ed --- /dev/null +++ b/front/src/libs/AstroUtils.ts @@ -0,0 +1,5 @@ +export default class AstroUtils { + public static async wrap(fn: () => T | Promise) { + return await fn() + } +} \ No newline at end of file -- 2.47.1 From 7c68628456d12a31a6d59b146df2ab614a86f5eb Mon Sep 17 00:00:00 2001 From: Clement Date: Sat, 20 Apr 2024 11:45:39 +0200 Subject: [PATCH 05/19] add register form test --- front/src/pages/account/register.astro | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 front/src/pages/account/register.astro diff --git a/front/src/pages/account/register.astro b/front/src/pages/account/register.astro new file mode 100644 index 0000000..a73cb13 --- /dev/null +++ b/front/src/pages/account/register.astro @@ -0,0 +1,44 @@ +--- +import PocketBase from 'pocketbase'; +import Layout from '../../layouts/Layout.astro'; +import AstroUtils from '../../libs/AstroUtils'; + +//const connected = await getUser(Astro.cookies) + +// if(connected) { +// return Astro.redirect(route('/')) +// } + + +const res = await AstroUtils.wrap(async () => { + if (Astro.request.method !== 'POST'){ + return + } + const form = await Astro.request.formData() + const request = { + username: form.get("username") as String, + name: form.get("name") as String, + email: form.get("email") as String, + password: form.get("password") as String, + passwordConfirm: form.get("passwordConfirm") as String, + emailVisibility: false + } + const pb = new PocketBase('http://127.0.0.1:3001'); + + console.log(request); + const record = await pb.collection('users').create(request); + console.log(record); + +}) +--- + + +
+ + + + + + +
+
\ No newline at end of file -- 2.47.1 From a724c1270f6f15ac7c06d441c21f49b0602fe0db Mon Sep 17 00:00:00 2001 From: Clement Date: Sat, 20 Apr 2024 12:07:37 +0200 Subject: [PATCH 06/19] fix: change register form name --- front/src/pages/account/register.astro | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/front/src/pages/account/register.astro b/front/src/pages/account/register.astro index a73cb13..54c4d53 100644 --- a/front/src/pages/account/register.astro +++ b/front/src/pages/account/register.astro @@ -34,8 +34,8 @@ const res = await AstroUtils.wrap(async () => {
- - + + -- 2.47.1 From 70382d7bd853a7011b1a5607da365b71a6b4dedc Mon Sep 17 00:00:00 2001 From: Clement Date: Sat, 20 Apr 2024 12:08:49 +0200 Subject: [PATCH 07/19] feat: login page test --- front/src/pages/account/login.astro | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 front/src/pages/account/login.astro diff --git a/front/src/pages/account/login.astro b/front/src/pages/account/login.astro new file mode 100644 index 0000000..a597d49 --- /dev/null +++ b/front/src/pages/account/login.astro @@ -0,0 +1,46 @@ +--- +import Layout from "../../layouts/Layout.astro"; +import PocketBase from 'pocketbase'; +import AstroUtils from "../../libs/AstroUtils"; +import Schema from 'models/Schema' + + +// const usr = await getUser(Astro.cookies) +// if (usr) { +// return Astro.redirect(route('/', {message: 'Vous êtes déjà connecté !'})) +// } + + +const res = await AstroUtils.wrap(async () => { + if (Astro.request.method !== 'POST') { + return + } + const form = await Astro.request.formData(); + const request = { + email: form.get("username") as String, + password: form.get("password") as String + } + const pb = new PocketBase('http://127.0.0.1:3001'); + + const authData = await pb.collection('users').authWithPassword( + request.email, + request.password, + ); + + console.log(authData) + + // after the above you can also access the auth data from the authStore + console.log(pb.authStore.isValid); + console.log(pb.authStore.token); + console.log(pb.authStore.model.id); + +}) +--- + + + + + + + + \ No newline at end of file -- 2.47.1 From 5a49f5beda671f3371bb13397baf8b063810ad20 Mon Sep 17 00:00:00 2001 From: Clement Date: Sat, 20 Apr 2024 12:09:05 +0200 Subject: [PATCH 08/19] rm some log --- front/src/pages/account/login.astro | 2 -- 1 file changed, 2 deletions(-) diff --git a/front/src/pages/account/login.astro b/front/src/pages/account/login.astro index a597d49..3717ce2 100644 --- a/front/src/pages/account/login.astro +++ b/front/src/pages/account/login.astro @@ -27,8 +27,6 @@ const res = await AstroUtils.wrap(async () => { request.password, ); - console.log(authData) - // after the above you can also access the auth data from the authStore console.log(pb.authStore.isValid); console.log(pb.authStore.token); -- 2.47.1 From 4caafb8c55150594ba9f40b320dc40270e3770d7 Mon Sep 17 00:00:00 2001 From: Clement Date: Sat, 20 Apr 2024 12:22:46 +0200 Subject: [PATCH 09/19] feat: add dockerfile front --- front/Dockerfile | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 front/Dockerfile diff --git a/front/Dockerfile b/front/Dockerfile new file mode 100644 index 0000000..a2ed561 --- /dev/null +++ b/front/Dockerfile @@ -0,0 +1,64 @@ +# This Dockerfile allows you to run AstroJS in server mode + +######### +# Build # +######### +FROM docker.io/node:20-alpine as BUILD_IMAGE + +# Disable telemetry +ENV ASTRO_TELEMETRY_DISABLED=1 + +# External deps (for node-gyp add: "python3 make g++") +RUN apk add --no-cache git + +# run as non root user +USER node + +# go to user repository +WORKDIR /home/node + +# Add package json +ADD --chown=node:node package.json package-lock.json ./ + +# install dependencies from package lock +RUN npm ci + +# Add project files +ADD --chown=node:node . . + +# build +RUN npm run build + +# remove dev deps +RUN npm prune --omit=dev + +############## +# Production # +############## +FROM docker.io/node:20-alpine as PROD_IMAGE + +# inform software to be in production +ENV NODE_ENV=production +ENV HOST=0.0.0.0 +ENV RESOURCES_FOLDER=/home/node/.loop/uploads +ENV ASTRO_TELEMETRY_DISABLED=1 + +# run as non root user +USER node + +# go to work folder +WORKDIR /home/node + +# Expose port +EXPOSE 3000 + +# Add Healthcheck +HEALTHCHECK --interval=10s --timeout=10s --start-period=5s --retries=3 CMD wget --no-verbose --tries=1 --spider http://localhost:3000 || exit 1 + +# copy from build image +COPY --chown=node:node --from=BUILD_IMAGE /home/node/node_modules ./node_modules +COPY --chown=node:node --from=BUILD_IMAGE /home/node/dist ./dist +COPY --chown=node:node --from=BUILD_IMAGE /home/node/package.json /home/node/.env* ./ + +# run it ! +CMD ["npm", "run", "start"] -- 2.47.1 From 28f47a933a0f723544e13fd8a52dd60f0a916aad Mon Sep 17 00:00:00 2001 From: Clement Date: Sat, 20 Apr 2024 12:22:59 +0200 Subject: [PATCH 10/19] add docker ci --- .github/workflows/build_docker.yml | 53 ++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/build_docker.yml diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml new file mode 100644 index 0000000..59228ca --- /dev/null +++ b/.github/workflows/build_docker.yml @@ -0,0 +1,53 @@ +name: Build Docker Image # nom du workflow + +on: #declancheur + push: + branches: + - '*' + tags: + - v* + pull_request: + branches: + - master + +jobs: + run: #jobs ID (nom du jobs) + runs-on: ubuntu-latest # environement de run + + steps: # liste des étapes + - name: Checkout # rapatrie le depot + uses: actions/checkout@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + git.lab-ouest.org/Epitech/ratrapage_T-WEB + tags: | + type=edge + type=ref,event=pr + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=semver,pattern=latest + + - name: Login to Gitea + uses: docker/login-action@v3 + with: + registry: git.lab-ouest.org + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + + # - name: Set up Docker Buildx + # uses: docker/setup-buildx-action@v3 + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + push: true + file: ./Dockerfile + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} -- 2.47.1 From 77f26f42e663bc00dc82d9501076119a7cdce278 Mon Sep 17 00:00:00 2001 From: Clement Date: Sat, 20 Apr 2024 13:15:38 +0200 Subject: [PATCH 11/19] fix CI/CD --- .github/workflows/build_docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index 59228ca..eb748f9 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -23,7 +23,7 @@ jobs: uses: docker/metadata-action@v5 with: images: | - git.lab-ouest.org/Epitech/ratrapage_T-WEB + git.lab-ouest.org/Epitech/ratrapage_T-WEB/front tags: | type=edge type=ref,event=pr -- 2.47.1 From bca06eef2ceef5176c2f9bf88113de248953c129 Mon Sep 17 00:00:00 2001 From: Clement Date: Sat, 20 Apr 2024 13:18:58 +0200 Subject: [PATCH 12/19] fix: build and push --- .github/workflows/build_docker.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index eb748f9..10882d8 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -23,7 +23,7 @@ jobs: uses: docker/metadata-action@v5 with: images: | - git.lab-ouest.org/Epitech/ratrapage_T-WEB/front + git.lab-ouest.org/Epitech/ratrapage_T-WEB tags: | type=edge type=ref,event=pr @@ -43,11 +43,11 @@ jobs: # - name: Set up Docker Buildx # uses: docker/setup-buildx-action@v3 - - name: Build and push + - name: Build and push front uses: docker/build-push-action@v5 with: context: . push: true - file: ./Dockerfile + file: ./front/Dockerfile tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} -- 2.47.1 From 19edb3472fedb7c98e9f9719ef8bdfbd5897f091 Mon Sep 17 00:00:00 2001 From: Clement Date: Sat, 20 Apr 2024 13:34:17 +0200 Subject: [PATCH 13/19] fix: build and push --- .github/workflows/build_docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml index 10882d8..c7b876a 100644 --- a/.github/workflows/build_docker.yml +++ b/.github/workflows/build_docker.yml @@ -46,7 +46,7 @@ jobs: - name: Build and push front uses: docker/build-push-action@v5 with: - context: . + context: ./front push: true file: ./front/Dockerfile tags: ${{ steps.meta.outputs.tags }} -- 2.47.1 From ccb31a172d6877c42815a524b02153320d789f86 Mon Sep 17 00:00:00 2001 From: Clement Date: Sat, 20 Apr 2024 13:57:37 +0200 Subject: [PATCH 14/19] fix build error --- front/src/pages/account/login.astro | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/front/src/pages/account/login.astro b/front/src/pages/account/login.astro index 3717ce2..80be112 100644 --- a/front/src/pages/account/login.astro +++ b/front/src/pages/account/login.astro @@ -2,7 +2,7 @@ import Layout from "../../layouts/Layout.astro"; import PocketBase from 'pocketbase'; import AstroUtils from "../../libs/AstroUtils"; -import Schema from 'models/Schema' +// import Schema from 'models/Schema' // const usr = await getUser(Astro.cookies) @@ -17,8 +17,8 @@ const res = await AstroUtils.wrap(async () => { } const form = await Astro.request.formData(); const request = { - email: form.get("username") as String, - password: form.get("password") as String + email: form.get("username") as string, + password: form.get("password") as string, } const pb = new PocketBase('http://127.0.0.1:3001'); @@ -30,7 +30,9 @@ const res = await AstroUtils.wrap(async () => { // after the above you can also access the auth data from the authStore console.log(pb.authStore.isValid); console.log(pb.authStore.token); - console.log(pb.authStore.model.id); + if(pb.authStore.model){ + console.log(pb.authStore.model.id); + } }) --- -- 2.47.1 From e3449076b3c5b28da5f156811e4e60472c5ec6dc Mon Sep 17 00:00:00 2001 From: Clement Date: Sat, 20 Apr 2024 14:19:50 +0200 Subject: [PATCH 15/19] feat: docker prod pocketbase --- docker-compose.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..98a69ba --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,22 @@ +version: "3.8" +services: + pocketbase: + image: ghcr.io/coollabsio/pocketbase:latest + environment: + - SERVICE_FQDN_POCKETBASE_8080 + volumes: + - ./.pb/pocketbase-data:/app/pb_data + - ./.pb/pocketbase-hooks:/app/pb_hooks + labels: + - traefik.enable=true + - traefik.http.routers.poketBaseTweb.rule=Host(`pb-tweb.cb85.fr`) + - traefik.http.services.poketBaseTweb.loadbalancer.server.port=8080 + - traefik.http.routers.poketBaseTweb.tls.certresolver=le + networks: + - public +networks: + public: + external: true +x-dockge: + urls: + - https://pb-tweb.cb85.fr/ -- 2.47.1 From ab5bad37c0c9437b5f68e3a5581f340b22c7b7f2 Mon Sep 17 00:00:00 2001 From: Clement Date: Sat, 20 Apr 2024 14:50:31 +0200 Subject: [PATCH 16/19] add front and env variable --- docker-compose.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 98a69ba..b0d0e52 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,14 +9,24 @@ services: - ./.pb/pocketbase-hooks:/app/pb_hooks labels: - traefik.enable=true - - traefik.http.routers.poketBaseTweb.rule=Host(`pb-tweb.cb85.fr`) - - traefik.http.services.poketBaseTweb.loadbalancer.server.port=8080 + - traefik.http.routers.poketBaseTweb.rule=Host(`${POCKET_BASE_URL}`) + - traefik.http.services.poketBaseTweb.loadbalancer.server.port=${POCKET_BASE_PORT} - traefik.http.routers.poketBaseTweb.tls.certresolver=le networks: - public + front: + image: git.lab-ouest.org + depends_on: + - pocketbase + labels: + - traefik.enable=true + - traefik.http.routers.astroTweb.rule=Host(`${FRONT_URL}`) + - traefik.http.services.astroTweb.loadbalancer.server.port=${FRONT_BASE_PORT} + - traefik.http.routers.astroTweb.tls.certresolver=le networks: public: external: true x-dockge: urls: - - https://pb-tweb.cb85.fr/ + - https://${POCKET_BASE_URL}/ + - https://${FRONT_URL}/ -- 2.47.1 From 07d105c71ebdebdf6c97e1d925e2d9571094d7e7 Mon Sep 17 00:00:00 2001 From: Clement Date: Sat, 20 Apr 2024 15:10:28 +0200 Subject: [PATCH 17/19] WIP update docker compose (dont work) --- docker-compose.yml | 4 +++- front/src/pages/account/register.astro | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index b0d0e52..39eeba4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,7 +15,7 @@ services: networks: - public front: - image: git.lab-ouest.org + image: git.lab-ouest.org/epitech/ratrapage_t-web:pr-2-head depends_on: - pocketbase labels: @@ -23,6 +23,8 @@ services: - traefik.http.routers.astroTweb.rule=Host(`${FRONT_URL}`) - traefik.http.services.astroTweb.loadbalancer.server.port=${FRONT_BASE_PORT} - traefik.http.routers.astroTweb.tls.certresolver=le + networks: + - public networks: public: external: true diff --git a/front/src/pages/account/register.astro b/front/src/pages/account/register.astro index 54c4d53..9b08d6d 100644 --- a/front/src/pages/account/register.astro +++ b/front/src/pages/account/register.astro @@ -30,6 +30,7 @@ const res = await AstroUtils.wrap(async () => { console.log(record); }) +return res --- -- 2.47.1 From d876439b500cc478b4999a2a09857c7151f1573b Mon Sep 17 00:00:00 2001 From: Clement Date: Sun, 21 Apr 2024 15:19:08 +0200 Subject: [PATCH 18/19] fix: remove file from other branch --- front/src/pages/account/login.astro | 46 ------------------- front/src/pages/account/register.astro | 45 ------------------ .../src/pages/{welcome.astro => index.astro} | 0 3 files changed, 91 deletions(-) delete mode 100644 front/src/pages/account/login.astro delete mode 100644 front/src/pages/account/register.astro rename front/src/pages/{welcome.astro => index.astro} (100%) diff --git a/front/src/pages/account/login.astro b/front/src/pages/account/login.astro deleted file mode 100644 index 80be112..0000000 --- a/front/src/pages/account/login.astro +++ /dev/null @@ -1,46 +0,0 @@ ---- -import Layout from "../../layouts/Layout.astro"; -import PocketBase from 'pocketbase'; -import AstroUtils from "../../libs/AstroUtils"; -// import Schema from 'models/Schema' - - -// const usr = await getUser(Astro.cookies) -// if (usr) { -// return Astro.redirect(route('/', {message: 'Vous êtes déjà connecté !'})) -// } - - -const res = await AstroUtils.wrap(async () => { - if (Astro.request.method !== 'POST') { - return - } - const form = await Astro.request.formData(); - const request = { - email: form.get("username") as string, - password: form.get("password") as string, - } - const pb = new PocketBase('http://127.0.0.1:3001'); - - const authData = await pb.collection('users').authWithPassword( - request.email, - request.password, - ); - - // after the above you can also access the auth data from the authStore - console.log(pb.authStore.isValid); - console.log(pb.authStore.token); - if(pb.authStore.model){ - console.log(pb.authStore.model.id); - } - -}) ---- - - -
- - - -
-
\ No newline at end of file diff --git a/front/src/pages/account/register.astro b/front/src/pages/account/register.astro deleted file mode 100644 index 9b08d6d..0000000 --- a/front/src/pages/account/register.astro +++ /dev/null @@ -1,45 +0,0 @@ ---- -import PocketBase from 'pocketbase'; -import Layout from '../../layouts/Layout.astro'; -import AstroUtils from '../../libs/AstroUtils'; - -//const connected = await getUser(Astro.cookies) - -// if(connected) { -// return Astro.redirect(route('/')) -// } - - -const res = await AstroUtils.wrap(async () => { - if (Astro.request.method !== 'POST'){ - return - } - const form = await Astro.request.formData() - const request = { - username: form.get("username") as String, - name: form.get("name") as String, - email: form.get("email") as String, - password: form.get("password") as String, - passwordConfirm: form.get("passwordConfirm") as String, - emailVisibility: false - } - const pb = new PocketBase('http://127.0.0.1:3001'); - - console.log(request); - const record = await pb.collection('users').create(request); - console.log(record); - -}) -return res ---- - - -
- - - - - - -
-
\ No newline at end of file diff --git a/front/src/pages/welcome.astro b/front/src/pages/index.astro similarity index 100% rename from front/src/pages/welcome.astro rename to front/src/pages/index.astro -- 2.47.1 From de3ab9a529c033bf29c5c46b98960f5fadd54118 Mon Sep 17 00:00:00 2001 From: Clement Date: Sun, 21 Apr 2024 15:22:34 +0200 Subject: [PATCH 19/19] fix rm file 2 form other branch --- front/src/layouts/Layout.astro | 31 ++++++++++++++++++++++++++++++- front/src/libs/AstroUtils.ts | 5 ----- 2 files changed, 30 insertions(+), 6 deletions(-) delete mode 100644 front/src/libs/AstroUtils.ts diff --git a/front/src/layouts/Layout.astro b/front/src/layouts/Layout.astro index 5c9eaae..7b552be 100644 --- a/front/src/layouts/Layout.astro +++ b/front/src/layouts/Layout.astro @@ -19,4 +19,33 @@ const { title } = Astro.props; - \ No newline at end of file + + diff --git a/front/src/libs/AstroUtils.ts b/front/src/libs/AstroUtils.ts deleted file mode 100644 index c97a8ed..0000000 --- a/front/src/libs/AstroUtils.ts +++ /dev/null @@ -1,5 +0,0 @@ -export default class AstroUtils { - public static async wrap(fn: () => T | Promise) { - return await fn() - } -} \ No newline at end of file -- 2.47.1