diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c69b376..3e49c32 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -84,6 +84,18 @@ jobs: - name: Checkout uses: actions/checkout@v3.5.0 + - name: Set up Node + uses: actions/setup-node@v3.6.0 + with: + cache: 'npm' + cache-dependency-path: 'backend/package-lock.json' + node-version: '18' + + - name: Install dependencies + run: | + cd backend + npm ci + - name: Deploy backend uses: cloudflare/wrangler-action@2.0.0 with: @@ -94,5 +106,8 @@ jobs: - name: Run Integration Tests uses: grafana/k6-action@v0.3.0 + env: + ENV: staging + PSK: ${{ secrets.BLOG_ADMIN_TOKEN }} with: filename: backend/test/script.js diff --git a/backend/.gitignore b/backend/.gitignore index 3c3629e..6ddea64 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -1 +1,2 @@ node_modules +.dev.vars diff --git a/backend/README.md b/backend/README.md new file mode 100644 index 0000000..2ccfb20 --- /dev/null +++ b/backend/README.md @@ -0,0 +1,14 @@ +## Backend + +### Development + +``` +# .dev.vars +TOKEN=${TOKEN} +``` + +### Testing + +``` +k6 -e PSK=${TOKEN} test/script.js +``` diff --git a/backend/package-lock.json b/backend/package-lock.json index 2963e15..73784f3 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -7,6 +7,9 @@ "": { "name": "blog", "version": "0.0.0", + "dependencies": { + "hono": "^3.6.1" + }, "devDependencies": { "wrangler": "^3.6.0" } @@ -21,9 +24,9 @@ } }, "node_modules/@cloudflare/workerd-darwin-64": { - "version": "1.20230814.1", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-64/-/workerd-darwin-64-1.20230814.1.tgz", - "integrity": "sha512-aQUO7q7qXl+SVtOiMMlVKLNOSeL6GX43RKeflwzsD74dGgyHPiSfw5KCvXhkVbyN7u+yYF6HyFdaIvHLfn5jyA==", + "version": "1.20230904.0", + "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-64/-/workerd-darwin-64-1.20230904.0.tgz", + "integrity": "sha512-/GDlmxAFbDtrQwP4zOXFbqOfaPvkDxdsCoEa+KEBcAl5uR98+7WW5/b8naBHX+t26uS7p4bLlImM8J5F1ienRQ==", "cpu": [ "x64" ], @@ -37,9 +40,9 @@ } }, "node_modules/@cloudflare/workerd-darwin-arm64": { - "version": "1.20230814.1", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-arm64/-/workerd-darwin-arm64-1.20230814.1.tgz", - "integrity": "sha512-U2mcgi+AiuI/4EY5Wk/GmygiNoCNw/V2mcHmxESqe4r6XbJYOzBdEsjnqJ05rqd0JlEM8m64jRtE6/qBnQHygg==", + "version": "1.20230904.0", + "resolved": "https://registry.npmjs.org/@cloudflare/workerd-darwin-arm64/-/workerd-darwin-arm64-1.20230904.0.tgz", + "integrity": "sha512-x8WXNc2xnDqr5y1iirnNdyx8GZY3rL5xiF7ebK3mKQeB+jFjkhO71yuPTkDCzUWtOvw1Wfd4jbwy4wxacMX4mQ==", "cpu": [ "arm64" ], @@ -53,9 +56,9 @@ } }, "node_modules/@cloudflare/workerd-linux-64": { - "version": "1.20230814.1", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-64/-/workerd-linux-64-1.20230814.1.tgz", - "integrity": "sha512-Q4kITXLTCuG2i2Z01fbb5AjVRRIf3+lS4ZVsFbTbIwtcOOG4Ozcw7ee7tKsFES7hFqR4Eg9gMG4/aS0mmi+L2g==", + "version": "1.20230904.0", + "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-64/-/workerd-linux-64-1.20230904.0.tgz", + "integrity": "sha512-V58xyMS3oDpKO8Dpdh0r0BXm99OzoGgvWe9ufttVraj/1NTMGELwb6i9ySb8k3F1J9m/sO26+TV7pQc/bGC1VQ==", "cpu": [ "x64" ], @@ -69,9 +72,9 @@ } }, "node_modules/@cloudflare/workerd-linux-arm64": { - "version": "1.20230814.1", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-arm64/-/workerd-linux-arm64-1.20230814.1.tgz", - "integrity": "sha512-BX5SaksXw+pkREVw3Rw2eSNXplqZw+14CcwW/5x/4oq/C6yn5qCvKxJfM7pukJGMI4wkJPOYops7B3g27FB/HA==", + "version": "1.20230904.0", + "resolved": "https://registry.npmjs.org/@cloudflare/workerd-linux-arm64/-/workerd-linux-arm64-1.20230904.0.tgz", + "integrity": "sha512-VrDaW+pjb5IAKEnNWtEaFiG377kXKmk5Fu0Era4W+jKzPON2BW/qRb/4LNHXQ4yxg/2HLm7RiUTn7JZtt1qO6A==", "cpu": [ "arm64" ], @@ -85,9 +88,9 @@ } }, "node_modules/@cloudflare/workerd-windows-64": { - "version": "1.20230814.1", - "resolved": "https://registry.npmjs.org/@cloudflare/workerd-windows-64/-/workerd-windows-64-1.20230814.1.tgz", - "integrity": "sha512-GWHqfyhsG/1wm2W8afkYX3q3fWXUWWD8NGtHfAs6ZVTHdW3mmYyMhKR0lc6ptBwz5i5aXRlP2S+CxxxwwDbKpw==", + "version": "1.20230904.0", + "resolved": "https://registry.npmjs.org/@cloudflare/workerd-windows-64/-/workerd-windows-64-1.20230904.0.tgz", + "integrity": "sha512-/R/dE8uy+8J2YeXfDhI8/Bg7YUirdbbjH5/l/Vv00ZRE0lC3nPLcYeyBXSwXIQ6/Xht3gN+lksLQgKd0ZWRd+Q==", "cpu": [ "x64" ], @@ -101,18 +104,18 @@ } }, "node_modules/@esbuild-plugins/node-globals-polyfill": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/@esbuild-plugins/node-globals-polyfill/-/node-globals-polyfill-0.1.1.tgz", - "integrity": "sha512-MR0oAA+mlnJWrt1RQVQ+4VYuRJW/P2YmRTv1AsplObyvuBMnPHiizUF95HHYiSsMGLhyGtWufaq2XQg6+iurBg==", + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/@esbuild-plugins/node-globals-polyfill/-/node-globals-polyfill-0.2.3.tgz", + "integrity": "sha512-r3MIryXDeXDOZh7ih1l/yE9ZLORCd5e8vWg02azWRGj5SPTuoh69A2AIyn0Z31V/kHBfZ4HgWJ+OK3GTTwLmnw==", "dev": true, "peerDependencies": { "esbuild": "*" } }, "node_modules/@esbuild-plugins/node-modules-polyfill": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/@esbuild-plugins/node-modules-polyfill/-/node-modules-polyfill-0.1.4.tgz", - "integrity": "sha512-uZbcXi0zbmKC/050p3gJnne5Qdzw8vkXIv+c2BW0Lsc1ji1SkrxbKPUy5Efr0blbTu1SL8w4eyfpnSdPg3G0Qg==", + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/@esbuild-plugins/node-modules-polyfill/-/node-modules-polyfill-0.2.2.tgz", + "integrity": "sha512-LXV7QsWJxRuMYvKbiznh+U1ilIop3g2TeKRzUxOG5X3YITc8JyyTa90BmLwqqv0YnX4v32CSlG+vsziZp9dMvA==", "dev": true, "dependencies": { "escape-string-regexp": "^4.0.0", @@ -123,9 +126,9 @@ } }, "node_modules/@esbuild/android-arm": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.16.3.tgz", - "integrity": "sha512-mueuEoh+s1eRbSJqq9KNBQwI4QhQV6sRXIfTyLXSHGMpyew61rOK4qY21uKbXl1iBoMb0AdL1deWFCQVlN2qHA==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.17.19.tgz", + "integrity": "sha512-rIKddzqhmav7MSmoFCmDIb6e2W57geRsM94gV2l38fzhXMwq7hZoClug9USI2pFRGL06f4IOPHHpFNOkWieR8A==", "cpu": [ "arm" ], @@ -139,9 +142,9 @@ } }, "node_modules/@esbuild/android-arm64": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.16.3.tgz", - "integrity": "sha512-RolFVeinkeraDvN/OoRf1F/lP0KUfGNb5jxy/vkIMeRRChkrX/HTYN6TYZosRJs3a1+8wqpxAo5PI5hFmxyPRg==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.17.19.tgz", + "integrity": "sha512-KBMWvEZooR7+kzY0BtbTQn0OAYY7CsiydT63pVEaPtVYF0hXbUaOyZog37DKxK7NF3XacBJOpYT4adIJh+avxA==", "cpu": [ "arm64" ], @@ -155,9 +158,9 @@ } }, "node_modules/@esbuild/android-x64": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.16.3.tgz", - "integrity": "sha512-SFpTUcIT1bIJuCCBMCQWq1bL2gPTjWoLZdjmIhjdcQHaUfV41OQfho6Ici5uvvkMmZRXIUGpM3GxysP/EU7ifQ==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.17.19.tgz", + "integrity": "sha512-uUTTc4xGNDT7YSArp/zbtmbhO0uEEK9/ETW29Wk1thYUJBz3IVnvgEiEwEa9IeLyvnpKrWK64Utw2bgUmDveww==", "cpu": [ "x64" ], @@ -171,9 +174,9 @@ } }, "node_modules/@esbuild/darwin-arm64": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.16.3.tgz", - "integrity": "sha512-DO8WykMyB+N9mIDfI/Hug70Dk1KipavlGAecxS3jDUwAbTpDXj0Lcwzw9svkhxfpCagDmpaTMgxWK8/C/XcXvw==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.17.19.tgz", + "integrity": "sha512-80wEoCfF/hFKM6WE1FyBHc9SfUblloAWx6FJkFWTWiCoht9Mc0ARGEM47e67W9rI09YoUxJL68WHfDRYEAvOhg==", "cpu": [ "arm64" ], @@ -187,9 +190,9 @@ } }, "node_modules/@esbuild/darwin-x64": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.16.3.tgz", - "integrity": "sha512-uEqZQ2omc6BvWqdCiyZ5+XmxuHEi1SPzpVxXCSSV2+Sh7sbXbpeNhHIeFrIpRjAs0lI1FmA1iIOxFozKBhKgRQ==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.17.19.tgz", + "integrity": "sha512-IJM4JJsLhRYr9xdtLytPLSH9k/oxR3boaUIYiHkAawtwNOXKE8KoU8tMvryogdcT8AU+Bflmh81Xn6Q0vTZbQw==", "cpu": [ "x64" ], @@ -203,9 +206,9 @@ } }, "node_modules/@esbuild/freebsd-arm64": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.16.3.tgz", - "integrity": "sha512-nJansp3sSXakNkOD5i5mIz2Is/HjzIhFs49b1tjrPrpCmwgBmH9SSzhC/Z1UqlkivqMYkhfPwMw1dGFUuwmXhw==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.17.19.tgz", + "integrity": "sha512-pBwbc7DufluUeGdjSU5Si+P3SoMF5DQ/F/UmTSb8HXO80ZEAJmrykPyzo1IfNbAoaqw48YRpv8shwd1NoI0jcQ==", "cpu": [ "arm64" ], @@ -219,9 +222,9 @@ } }, "node_modules/@esbuild/freebsd-x64": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.16.3.tgz", - "integrity": "sha512-TfoDzLw+QHfc4a8aKtGSQ96Wa+6eimljjkq9HKR0rHlU83vw8aldMOUSJTUDxbcUdcgnJzPaX8/vGWm7vyV7ug==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.17.19.tgz", + "integrity": "sha512-4lu+n8Wk0XlajEhbEffdy2xy53dpR06SlzvhGByyg36qJw6Kpfk7cp45DR/62aPH9mtJRmIyrXAS5UWBrJT6TQ==", "cpu": [ "x64" ], @@ -235,9 +238,9 @@ } }, "node_modules/@esbuild/linux-arm": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.16.3.tgz", - "integrity": "sha512-VwswmSYwVAAq6LysV59Fyqk3UIjbhuc6wb3vEcJ7HEJUtFuLK9uXWuFoH1lulEbE4+5GjtHi3MHX+w1gNHdOWQ==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.17.19.tgz", + "integrity": "sha512-cdmT3KxjlOQ/gZ2cjfrQOtmhG4HJs6hhvm3mWSRDPtZ/lP5oe8FWceS10JaSJC13GBd4eH/haHnqf7hhGNLerA==", "cpu": [ "arm" ], @@ -251,9 +254,9 @@ } }, "node_modules/@esbuild/linux-arm64": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.16.3.tgz", - "integrity": "sha512-7I3RlsnxEFCHVZNBLb2w7unamgZ5sVwO0/ikE2GaYvYuUQs9Qte/w7TqWcXHtCwxvZx/2+F97ndiUQAWs47ZfQ==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.17.19.tgz", + "integrity": "sha512-ct1Tg3WGwd3P+oZYqic+YZF4snNl2bsnMKRkb3ozHmnM0dGWuxcPTTntAF6bOP0Sp4x0PjSF+4uHQ1xvxfRKqg==", "cpu": [ "arm64" ], @@ -267,9 +270,9 @@ } }, "node_modules/@esbuild/linux-ia32": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.16.3.tgz", - "integrity": "sha512-X8FDDxM9cqda2rJE+iblQhIMYY49LfvW4kaEjoFbTTQ4Go8G96Smj2w3BRTwA8IHGoi9dPOPGAX63dhuv19UqA==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.17.19.tgz", + "integrity": "sha512-w4IRhSy1VbsNxHRQpeGCHEmibqdTUx61Vc38APcsRbuVgK0OPEnQ0YD39Brymn96mOx48Y2laBQGqgZ0j9w6SQ==", "cpu": [ "ia32" ], @@ -283,9 +286,9 @@ } }, "node_modules/@esbuild/linux-loong64": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.16.3.tgz", - "integrity": "sha512-hIbeejCOyO0X9ujfIIOKjBjNAs9XD/YdJ9JXAy1lHA+8UXuOqbFe4ErMCqMr8dhlMGBuvcQYGF7+kO7waj2KHw==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.17.19.tgz", + "integrity": "sha512-2iAngUbBPMq439a+z//gE+9WBldoMp1s5GWsUSgqHLzLJ9WoZLZhpwWuym0u0u/4XmZ3gpHmzV84PonE+9IIdQ==", "cpu": [ "loong64" ], @@ -299,9 +302,9 @@ } }, "node_modules/@esbuild/linux-mips64el": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.16.3.tgz", - "integrity": "sha512-znFRzICT/V8VZQMt6rjb21MtAVJv/3dmKRMlohlShrbVXdBuOdDrGb+C2cZGQAR8RFyRe7HS6klmHq103WpmVw==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.17.19.tgz", + "integrity": "sha512-LKJltc4LVdMKHsrFe4MGNPp0hqDFA1Wpt3jE1gEyM3nKUvOiO//9PheZZHfYRfYl6AwdTH4aTcXSqBerX0ml4A==", "cpu": [ "mips64el" ], @@ -315,9 +318,9 @@ } }, "node_modules/@esbuild/linux-ppc64": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.16.3.tgz", - "integrity": "sha512-EV7LuEybxhXrVTDpbqWF2yehYRNz5e5p+u3oQUS2+ZFpknyi1NXxr8URk4ykR8Efm7iu04//4sBg249yNOwy5Q==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.17.19.tgz", + "integrity": "sha512-/c/DGybs95WXNS8y3Ti/ytqETiW7EU44MEKuCAcpPto3YjQbyK3IQVKfF6nbghD7EcLUGl0NbiL5Rt5DMhn5tg==", "cpu": [ "ppc64" ], @@ -331,9 +334,9 @@ } }, "node_modules/@esbuild/linux-riscv64": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.16.3.tgz", - "integrity": "sha512-uDxqFOcLzFIJ+r/pkTTSE9lsCEaV/Y6rMlQjUI9BkzASEChYL/aSQjZjchtEmdnVxDKETnUAmsaZ4pqK1eE5BQ==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.17.19.tgz", + "integrity": "sha512-FC3nUAWhvFoutlhAkgHf8f5HwFWUL6bYdvLc/TTuxKlvLi3+pPzdZiFKSWz/PF30TB1K19SuCxDTI5KcqASJqA==", "cpu": [ "riscv64" ], @@ -347,9 +350,9 @@ } }, "node_modules/@esbuild/linux-s390x": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.16.3.tgz", - "integrity": "sha512-NbeREhzSxYwFhnCAQOQZmajsPYtX71Ufej3IQ8W2Gxskfz9DK58ENEju4SbpIj48VenktRASC52N5Fhyf/aliQ==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.17.19.tgz", + "integrity": "sha512-IbFsFbxMWLuKEbH+7sTkKzL6NJmG2vRyy6K7JJo55w+8xDk7RElYn6xvXtDW8HCfoKBFK69f3pgBJSUSQPr+4Q==", "cpu": [ "s390x" ], @@ -363,9 +366,9 @@ } }, "node_modules/@esbuild/linux-x64": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.16.3.tgz", - "integrity": "sha512-SDiG0nCixYO9JgpehoKgScwic7vXXndfasjnD5DLbp1xltANzqZ425l7LSdHynt19UWOcDjG9wJJzSElsPvk0w==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.17.19.tgz", + "integrity": "sha512-68ngA9lg2H6zkZcyp22tsVt38mlhWde8l3eJLWkyLrp4HwMUr3c1s/M2t7+kHIhvMjglIBrFpncX1SzMckomGw==", "cpu": [ "x64" ], @@ -379,9 +382,9 @@ } }, "node_modules/@esbuild/netbsd-x64": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.16.3.tgz", - "integrity": "sha512-AzbsJqiHEq1I/tUvOfAzCY15h4/7Ivp3ff/o1GpP16n48JMNAtbW0qui2WCgoIZArEHD0SUQ95gvR0oSO7ZbdA==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.17.19.tgz", + "integrity": "sha512-CwFq42rXCR8TYIjIfpXCbRX0rp1jo6cPIUPSaWwzbVI4aOfX96OXY8M6KNmtPcg7QjYeDmN+DD0Wp3LaBOLf4Q==", "cpu": [ "x64" ], @@ -395,9 +398,9 @@ } }, "node_modules/@esbuild/openbsd-x64": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.16.3.tgz", - "integrity": "sha512-gSABi8qHl8k3Cbi/4toAzHiykuBuWLZs43JomTcXkjMZVkp0gj3gg9mO+9HJW/8GB5H89RX/V0QP4JGL7YEEVg==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.17.19.tgz", + "integrity": "sha512-cnq5brJYrSZ2CF6c35eCmviIN3k3RczmHz8eYaVlNasVqsNY+JKohZU5MKmaOI+KkllCdzOKKdPs762VCPC20g==", "cpu": [ "x64" ], @@ -411,9 +414,9 @@ } }, "node_modules/@esbuild/sunos-x64": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.16.3.tgz", - "integrity": "sha512-SF9Kch5Ete4reovvRO6yNjMxrvlfT0F0Flm+NPoUw5Z4Q3r1d23LFTgaLwm3Cp0iGbrU/MoUI+ZqwCv5XJijCw==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.17.19.tgz", + "integrity": "sha512-vCRT7yP3zX+bKWFeP/zdS6SqdWB8OIpaRq/mbXQxTGHnIxspRtigpkUcDMlSCOejlHowLqII7K2JKevwyRP2rg==", "cpu": [ "x64" ], @@ -427,9 +430,9 @@ } }, "node_modules/@esbuild/win32-arm64": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.16.3.tgz", - "integrity": "sha512-u5aBonZIyGopAZyOnoPAA6fGsDeHByZ9CnEzyML9NqntK6D/xl5jteZUKm/p6nD09+v3pTM6TuUIqSPcChk5gg==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.17.19.tgz", + "integrity": "sha512-yYx+8jwowUstVdorcMdNlzklLYhPxjniHWFKgRqH7IFlUEa0Umu3KuYplf1HUZZ422e3NU9F4LGb+4O0Kdcaag==", "cpu": [ "arm64" ], @@ -443,9 +446,9 @@ } }, "node_modules/@esbuild/win32-ia32": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.16.3.tgz", - "integrity": "sha512-GlgVq1WpvOEhNioh74TKelwla9KDuAaLZrdxuuUgsP2vayxeLgVc+rbpIv0IYF4+tlIzq2vRhofV+KGLD+37EQ==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.17.19.tgz", + "integrity": "sha512-eggDKanJszUtCdlVs0RB+h35wNlb5v4TWEkq4vZcmVt5u/HiDZrTXe2bWFQUez3RgNHwx/x4sk5++4NSSicKkw==", "cpu": [ "ia32" ], @@ -459,9 +462,9 @@ } }, "node_modules/@esbuild/win32-x64": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.16.3.tgz", - "integrity": "sha512-5/JuTd8OWW8UzEtyf19fbrtMJENza+C9JoPIkvItgTBQ1FO2ZLvjbPO6Xs54vk0s5JB5QsfieUEshRQfu7ZHow==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.17.19.tgz", + "integrity": "sha512-lAhycmKnVOuRYNtRtatQR1LPQf2oYCkRGkSFnseDAKPl8lu5SOsK/e1sXe5a0Pc5kHIHe6P2I/ilntNv2xf3cA==", "cpu": [ "x64" ], @@ -538,14 +541,14 @@ ] }, "node_modules/better-sqlite3": { - "version": "8.5.2", - "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-8.5.2.tgz", - "integrity": "sha512-w/EZ/jwuZF+/47mAVC2+rhR2X/gwkZ+fd1pbX7Y90D5NRaRzDQcxrHY10t6ijGiYIonCVsBSF5v1cay07bP5sg==", + "version": "8.6.0", + "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-8.6.0.tgz", + "integrity": "sha512-jwAudeiTMTSyby+/SfbHDebShbmC2MCH8mU2+DXi0WJfv13ypEJm47cd3kljmy/H130CazEvkf2Li//ewcMJ1g==", "dev": true, "hasInstallScript": true, "dependencies": { "bindings": "^1.5.0", - "prebuild-install": "^7.1.0" + "prebuild-install": "^7.1.1" } }, "node_modules/binary-extensions": { @@ -755,9 +758,9 @@ } }, "node_modules/esbuild": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.16.3.tgz", - "integrity": "sha512-71f7EjPWTiSguen8X/kxEpkAS7BFHwtQKisCDDV3Y4GLGWBaoSCyD5uXkaUew6JDzA9FEN1W23mdnSwW9kqCeg==", + "version": "0.17.19", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.17.19.tgz", + "integrity": "sha512-XQ0jAPFkK/u3LcVRcvVHQcTIqD6E2H1fvZMA5dQPSOWb3suUbWbfbRf94pjc0bNzRYLfIrDRQXr7X+LHIm5oHw==", "dev": true, "hasInstallScript": true, "bin": { @@ -767,28 +770,28 @@ "node": ">=12" }, "optionalDependencies": { - "@esbuild/android-arm": "0.16.3", - "@esbuild/android-arm64": "0.16.3", - "@esbuild/android-x64": "0.16.3", - "@esbuild/darwin-arm64": "0.16.3", - "@esbuild/darwin-x64": "0.16.3", - "@esbuild/freebsd-arm64": "0.16.3", - "@esbuild/freebsd-x64": "0.16.3", - "@esbuild/linux-arm": "0.16.3", - "@esbuild/linux-arm64": "0.16.3", - "@esbuild/linux-ia32": "0.16.3", - "@esbuild/linux-loong64": "0.16.3", - "@esbuild/linux-mips64el": "0.16.3", - "@esbuild/linux-ppc64": "0.16.3", - "@esbuild/linux-riscv64": "0.16.3", - "@esbuild/linux-s390x": "0.16.3", - "@esbuild/linux-x64": "0.16.3", - "@esbuild/netbsd-x64": "0.16.3", - "@esbuild/openbsd-x64": "0.16.3", - "@esbuild/sunos-x64": "0.16.3", - "@esbuild/win32-arm64": "0.16.3", - "@esbuild/win32-ia32": "0.16.3", - "@esbuild/win32-x64": "0.16.3" + "@esbuild/android-arm": "0.17.19", + "@esbuild/android-arm64": "0.17.19", + "@esbuild/android-x64": "0.17.19", + "@esbuild/darwin-arm64": "0.17.19", + "@esbuild/darwin-x64": "0.17.19", + "@esbuild/freebsd-arm64": "0.17.19", + "@esbuild/freebsd-x64": "0.17.19", + "@esbuild/linux-arm": "0.17.19", + "@esbuild/linux-arm64": "0.17.19", + "@esbuild/linux-ia32": "0.17.19", + "@esbuild/linux-loong64": "0.17.19", + "@esbuild/linux-mips64el": "0.17.19", + "@esbuild/linux-ppc64": "0.17.19", + "@esbuild/linux-riscv64": "0.17.19", + "@esbuild/linux-s390x": "0.17.19", + "@esbuild/linux-x64": "0.17.19", + "@esbuild/netbsd-x64": "0.17.19", + "@esbuild/openbsd-x64": "0.17.19", + "@esbuild/sunos-x64": "0.17.19", + "@esbuild/win32-arm64": "0.17.19", + "@esbuild/win32-ia32": "0.17.19", + "@esbuild/win32-x64": "0.17.19" } }, "node_modules/escape-string-regexp": { @@ -911,6 +914,14 @@ "integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==", "dev": true }, + "node_modules/hono": { + "version": "3.6.1", + "resolved": "https://registry.npmjs.org/hono/-/hono-3.6.1.tgz", + "integrity": "sha512-FaWXh0MSc2Hv2IrGI4vFvZEK69NHfggEgHUlNMXp2zrpKh23j7wS0Ku316Do9CFAl07OBNozBelcvruiBT8crQ==", + "engines": { + "node": ">=16.0.0" + } + }, "node_modules/http-cache-semantics": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz", @@ -1046,9 +1057,9 @@ } }, "node_modules/miniflare": { - "version": "3.20230814.1", - "resolved": "https://registry.npmjs.org/miniflare/-/miniflare-3.20230814.1.tgz", - "integrity": "sha512-LMgqd1Ut0+fnlvQepVbbBYQczQnyuuap8bgUwOyPETka0S9NR9NxMQSNaBgVZ0uOaG7xMJ/OVTRlz+TGB86PWA==", + "version": "3.20230904.0", + "resolved": "https://registry.npmjs.org/miniflare/-/miniflare-3.20230904.0.tgz", + "integrity": "sha512-+OWQqEk8hV7vZaPCoj5dk1lZr4YUy56OiyNZ45/3ITYf+ZxgQOBPWhQhpw1jCahkRKGPa9Aykz01sc+GhPZYDA==", "dev": true, "dependencies": { "acorn": "^8.8.0", @@ -1059,11 +1070,10 @@ "glob-to-regexp": "^0.4.1", "http-cache-semantics": "^4.1.0", "kleur": "^4.1.5", - "set-cookie-parser": "^2.6.0", "source-map-support": "0.5.21", "stoppable": "^1.1.0", - "undici": "^5.13.0", - "workerd": "1.20230814.1", + "undici": "^5.22.1", + "workerd": "1.20230904.0", "ws": "^8.11.0", "youch": "^3.2.2", "zod": "^3.20.6" @@ -1343,12 +1353,6 @@ "node": ">=10" } }, - "node_modules/set-cookie-parser": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-2.6.0.tgz", - "integrity": "sha512-RVnVQxTXuerk653XfuliOxBP81Sf0+qfQE73LIYKcyMYHG94AuH0kgrQpRDuTZnSmjpysHmzxJXKNfa6PjFhyQ==", - "dev": true - }, "node_modules/simple-concat": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz", @@ -1535,9 +1539,9 @@ } }, "node_modules/undici": { - "version": "5.23.0", - "resolved": "https://registry.npmjs.org/undici/-/undici-5.23.0.tgz", - "integrity": "sha512-1D7w+fvRsqlQ9GscLBwcAJinqcZGHUKjbOmXdlE/v8BvEGXjeWAax+341q44EuTcHXXnfyKNbKRq4Lg7OzhMmg==", + "version": "5.24.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.24.0.tgz", + "integrity": "sha512-OKlckxBjFl0oXxcj9FU6oB8fDAaiRUq+D8jrFWGmOfI/gIyjk/IeS75LMzgYKUaeHzLUcYvf9bbJGSrUwTfwwQ==", "dev": true, "dependencies": { "busboy": "^1.6.0" @@ -1553,9 +1557,9 @@ "dev": true }, "node_modules/workerd": { - "version": "1.20230814.1", - "resolved": "https://registry.npmjs.org/workerd/-/workerd-1.20230814.1.tgz", - "integrity": "sha512-zJeSEteXuAD+bpYJT8WvzTAHvIAkKPVxOV+Jy6zCLKz5e08N3OUbAF+wrvGWc8b2aB1sj+IYsdXfkv4puH+qXQ==", + "version": "1.20230904.0", + "resolved": "https://registry.npmjs.org/workerd/-/workerd-1.20230904.0.tgz", + "integrity": "sha512-t9znszH0rQGK4mJGvF9L3nN0qKEaObAGx0JkywFtAwH8OkSn+YfQbHNZE+YsJ4qa1hOz1DCNEk08UDFRBaYq4g==", "dev": true, "hasInstallScript": true, "bin": { @@ -1565,26 +1569,26 @@ "node": ">=16" }, "optionalDependencies": { - "@cloudflare/workerd-darwin-64": "1.20230814.1", - "@cloudflare/workerd-darwin-arm64": "1.20230814.1", - "@cloudflare/workerd-linux-64": "1.20230814.1", - "@cloudflare/workerd-linux-arm64": "1.20230814.1", - "@cloudflare/workerd-windows-64": "1.20230814.1" + "@cloudflare/workerd-darwin-64": "1.20230904.0", + "@cloudflare/workerd-darwin-arm64": "1.20230904.0", + "@cloudflare/workerd-linux-64": "1.20230904.0", + "@cloudflare/workerd-linux-arm64": "1.20230904.0", + "@cloudflare/workerd-windows-64": "1.20230904.0" } }, "node_modules/wrangler": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/wrangler/-/wrangler-3.6.0.tgz", - "integrity": "sha512-GWs4+gIUK+086svW/TgFhhxxrl/hdW2L7WASbdc10dJT7yFmCXse0SnHiqWUxbFu3ScP2t3a3LszJ08wwolWHg==", + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/wrangler/-/wrangler-3.8.0.tgz", + "integrity": "sha512-sTdD+6fMEpM9ROxv+gcyxgTKpnf7tB5ftRV5+wupsdljWkow5C00UCWU/IWSOUfuitAGAj1PWATjKfrRp9Bk9w==", "dev": true, "dependencies": { "@cloudflare/kv-asset-handler": "^0.2.0", - "@esbuild-plugins/node-globals-polyfill": "^0.1.1", - "@esbuild-plugins/node-modules-polyfill": "^0.1.4", + "@esbuild-plugins/node-globals-polyfill": "^0.2.3", + "@esbuild-plugins/node-modules-polyfill": "^0.2.2", "blake3-wasm": "^2.1.5", "chokidar": "^3.5.3", - "esbuild": "0.16.3", - "miniflare": "3.20230814.1", + "esbuild": "0.17.19", + "miniflare": "3.20230904.0", "nanoid": "^3.3.3", "path-to-regexp": "^6.2.0", "selfsigned": "^2.0.1", @@ -1609,9 +1613,9 @@ "dev": true }, "node_modules/ws": { - "version": "8.13.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.13.0.tgz", - "integrity": "sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==", + "version": "8.14.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.14.1.tgz", + "integrity": "sha512-4OOseMUq8AzRBI/7SLMUwO+FEDnguetSk7KMb1sHwvF2w2Wv5Hoj0nlifx8vtGsftE/jWHojPy8sMMzYLJ2G/A==", "dev": true, "engines": { "node": ">=10.0.0" @@ -1642,9 +1646,9 @@ "dev": true }, "node_modules/youch": { - "version": "3.2.3", - "resolved": "https://registry.npmjs.org/youch/-/youch-3.2.3.tgz", - "integrity": "sha512-ZBcWz/uzZaQVdCvfV4uk616Bbpf2ee+F/AvuKDR5EwX/Y4v06xWdtMluqTD7+KlZdM93lLm9gMZYo0sKBS0pgw==", + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/youch/-/youch-3.3.1.tgz", + "integrity": "sha512-Rg9ioi+AkKyje2Hk4qILSVvayaFW98KTsOJ4aIkjDf97LZX5WJVIHZmFLnM4ThcVofHo/fbbwtYajfBPHFOVtg==", "dev": true, "dependencies": { "cookie": "^0.5.0", diff --git a/backend/package.json b/backend/package.json index 7fb65e6..31188cc 100644 --- a/backend/package.json +++ b/backend/package.json @@ -3,10 +3,14 @@ "version": "0.0.0", "private": true, "scripts": { - "deploy": "wrangler deploy", - "start": "wrangler dev --remote" + "dev": "wrangler dev --remote", + "test": "k6 -e ENV=dev -e PSK=${TOKEN} run/script.js", + "deploy": "wrangler deploy" }, "devDependencies": { - "wrangler": "^3.6.0" + "wrangler": "^3.7.0" + }, + "dependencies": { + "hono": "^3.6.1" } } diff --git a/backend/src/worker.js b/backend/src/worker.js index 0ef8f65..f75dffc 100644 --- a/backend/src/worker.js +++ b/backend/src/worker.js @@ -1,40 +1,29 @@ -/** - * Welcome to Cloudflare Workers! This is your first worker. - * - * - Run `npm run dev` in your terminal to start a development server - * - Open a browser tab at http://localhost:8787/ to see your worker in action - * - Run `npm run deploy` to publish your worker - * - * Learn more at https://developers.cloudflare.com/workers/ - */ - -const corsHeaders = { - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Methods': 'GET', - 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept' -} - -const getRSS = async (key, env) => { - console.log(`RSS match found`) - const rssBlob = await env.BLOG_BUCKET.get(key); - - if (rssBlob === null) { - return new Response('Object Not Found', { status: 404 }); - } +import { Hono } from 'hono' +import { validator } from 'hono/validator' +import { bearerAuth } from 'hono/bearer-auth' +import { cors } from 'hono/cors' +import { etag } from 'hono/etag' + + +const app = new Hono() + +app.use('/*', cors()); +app.use('/*', etag()); + + +app.get('/rss.xml', async c => { + const rssBlob = await c.env.BLOG_BUCKET.get('rss.xml'); + + if (rssBlob === null) return c.text('Object not found', 404) + + c.header('content-type', 'application/xml') + c.header('etag', rssBlob.httpEtag) + return c.text(rssBlob.body, 200) +}) - if (env.FLAG_USE_HEADERS) { - return new Response(rssBlob.body, { status: 200, headers: { - ...corsHeaders, - 'etag': rssBlob.httpEtag, - 'Content-type': 'application/xml' - }}); - } else { - return new Response(rssBlob.body, { status: 200 }); - } -}; -const getPostList = async (key, env) => { - const postBlob = await env.BLOG_BUCKET.get('posts.json'); +app.get('/posts', async c => { + const postBlob = await c.env.BLOG_BUCKET.get('posts.json'); if (postBlob === null) { return new Response('Object Not Found', { status: 404 }); @@ -52,85 +41,112 @@ const getPostList = async (key, env) => { }) )) .then(postList => { - if (env.FLAG_USE_HEADERS) { - return new Response(JSON.stringify({ postList: postList }, null, 4), { - status: 200, - headers: { - ...corsHeaders, - 'etag': postBlob.httpEtag, - 'Content-type': 'application/json' - } - }); - } else { - return new Response(JSON.stringify({ postList: postList }, null, 4), { status: 200, }); - } + c.header('content-type', 'application/json') + c.header('etag', postBlob.httpEtag) + return c.text(JSON.stringify({ postList: postList }), 200) }) -} +}) + + +app.get('/posts/:slug', async c => { + const { slug } = c.req.param() -const getPost = async (key, env) => { - const postBlob = await env.BLOG_BUCKET.get('posts.json'); + const postBlob = await c.env.BLOG_BUCKET.get('posts.json'); if (postBlob === null) { return new Response('Object Not Found', { status: 404 }); } - - const postSlug = key.split("/")[1]; - return postBlob.json() - .then(posts => posts[postSlug]) + .then(posts => posts[slug]) .then(post => { - if (env.FLAG_USE_HEADERS) { - return new Response(JSON.stringify({ post: post }, null, 4), { - status: 200, - headers: { - ...corsHeaders, - 'etag': postBlob.httpEtag, - 'Content-type': 'application/json' - } - }); - } - return new Response(JSON.stringify({ post: post }, null, 4), { - status: 200, - }); + c.header('content-type', 'application/json') + c.header('etag', postBlob.httpEtag) + return c.text(JSON.stringify({ post: post}), 200) }) -} - -export default { - async fetch(request, env) { - const url = new URL(request.url); - const key = url.pathname.slice(1); - console.log(`key: ${key}`) - - const routeRSS = /rss.xml/, - routePostList = /posts$/, - routePost = /posts\/*/; - - switch (true) { - case routeRSS.test(key): - return getRSS(key, env); - break; - case routePostList.test(key): - return getPostList(key, env); - break; - case routePost.test(key): - return getPost(key, env); - break; - default: - if (env.FLAG_USE_HEADERS) { - return new Response(JSON.stringify({ message: `/${key} not found`}, null, 2), { - status: 404, - headers: { - ...corsHeaders, - 'Content-type': 'application/json', - 'My-Header-test': 'did it come through?' - }, - }); - } else { - return new Response(JSON.stringify({ message: `/${key} not found`}, null, 2), { - status: 404, - }); - } - break; +}) + + +app.post('/drip', async(c, next) => { + const token = c.env.TOKEN + const auth = bearerAuth({ + token + }) + return auth(c, next) +}) + + +app.post( + '/drip', + validator('header', (value, c) => { + if (!value["content-type"] || value["content-type"] != "application/json") { + return c.text("Invalid headers", 400) } - }, -}; + return value + }), + validator('json', (value, c) => { + if (!("message" in value)) return c.text('Invalid body', 400) + + return value + }), + async c => { + const headers = c.req.valid('header') + const body = c.req.valid('json') + + const action = 'id' in body ? 'update' : 'create' + const response = `POST called on /drip. Action: ${action}` + + if (action == "update") { + if (!("message" in body)) return c.text('Invalid body for update', 400) + + const { success } = await c.env.DB_DRIP.prepare(` + update drip set message=? where id=? + `).bind(body['message'], body['id']).run() + if (success) return c.text(JSON.stringify({ message: 'drip updated' }, null, 2), 201) + } else { + const { success } = await c.env.DB_DRIP.prepare(` + insert into drip (message) values (?) + `).bind(body['message']).run() + if (success) return c.text(JSON.stringify({ message: 'drip created' }, null, 2), 201) + } + + return c.text(JSON.stringify({ message: 'something went wrong'}, null, 2), 500) + } +) + + +app.get('/drip', async c => { + const { success, results } = await c.env.DB_DRIP.prepare(` + select * from drip ORDER BY created_at DESC LIMIT 1 + `).bind().all() + + if (!success) return c.text(JSON.stringify({ message: "something went wrong"}), 400) + + return c.text( JSON.stringify({ data: results }, null, 2), 200); + +}) + + +app.delete('/drip/*', async(c, next) => { + const token = c.env.TOKEN + const auth = bearerAuth({ + token + }) + return auth(c, next) +}) + + +app.delete( + '/drip/:id', + async c => { + const { id } = c.req.param() + const { success } = await c.env.DB_DRIP.prepare(` + delete from drip where id=? + `).bind(id).run() + + if (success) return c.text(JSON.stringify({ message: `drip deleted` }, null, 2), 201) + + return c.text('something went wrong', 400) + } +) + +export default app diff --git a/backend/test/script.js b/backend/test/script.js index 77c4e64..97da66f 100644 --- a/backend/test/script.js +++ b/backend/test/script.js @@ -12,12 +12,14 @@ export const options = { } */ -//let shortenLink +const SLEEP_TIME = 0.5 + +const BASE_URL = __ENV.ENV == "staging" ? "https://blog-backend-dev.flinnlab.workers.dev" : "http://localhost:8787" -const BASE_URL = "https://blog-dev.flinnlab.workers.dev" export default function () { - group('rss feed', function () { + // GROUP: rss + group('rss', function () { const res = http.get(`${BASE_URL}/rss.xml`) check(res, { @@ -25,28 +27,30 @@ export default function () { 'verify RSS feed': (r) => r.body.includes('flinnlab.com') }) - sleep(1) // second + sleep(SLEEP_TIME) // second }) - group('list of posts', function () { + + // GROUP: post + group('post', function () { const res = http.get(`${BASE_URL}/posts`) check(res, { - 'is status 200': (r) => r.status === 200, - 'is formatted correctly': (r) => 'postList' in r.json(), - 'is not empty': (r) => r.json()['postList'].length != 0 + 'postsPage: status is 200': (r) => r.status === 200, + 'postsPage: formatted correctly': (r) => 'postList' in r.json(), + 'postsPage: is not empty': (r) => r.json()['postList'].length != 0 }) - sleep(1) // second + sleep(SLEEP_TIME) // second }) group('post', function () { const res = http.get(`${BASE_URL}/posts/git-monorepo`) check(res, { - 'is status 200': (r) => r.status === 200, - 'is formatted correctly': (r) => 'post' in r.json(), - 'contains all metadata': (r) => { + 'postPage: status is 200': (r) => r.status === 200, + 'postPage: formatted correctly': (r) => 'post' in r.json(), + 'postPage: contains all metadata': (r) => { return ['slug', 'title', 'published', 'description', 'body'] .map(key => key in r.json()['post'] @@ -55,6 +59,74 @@ export default function () { } }) - sleep(1) // second + sleep(SLEEP_TIME) // second + }) + + + // GROUP: drip + group('drip', function () { + const res = http.get(`${BASE_URL}/drip`) + + const json = res.json() + check(res, { + 'GET: status is 200': (r) => r.status === 200, + 'GET: verify body': (r) => "data" in json + }) + + sleep(SLEEP_TIME) // second + }) + + group('drip', function () { + const res = http.post(`${BASE_URL}/drip`) + + check(res, { + 'POST - auth: status is 403': (r) => r.status === 401, + 'POST - auth: verify body': (r) => r.body.includes('Unauthorized') + }) + + sleep(SLEEP_TIME) // second + }) + + group('drip', function () { + const payload = JSON.stringify({ + message: 'hello', + }); + + const params = { + headers: { + 'Authorization': `Bearer ${__ENV.PSK}`, + 'Content-Type': 'application/json', + }, + }; + + const res = http.post(`${BASE_URL}/drip`, payload, params) + check(res, { + 'POST - create: status is 201': (r) => r.status === 201, + 'POST - create: verify body': (r) => r.body.includes('create') + }) + + sleep(SLEEP_TIME) // second + }) + + group('drip', function () { + const payload = JSON.stringify({ + id: 0, + message: 'hello', + }); + + const params = { + headers: { + 'Authorization': `Bearer ${__ENV.PSK}`, + 'Content-Type': 'application/json', + }, + }; + + const res = http.post(`${BASE_URL}/drip`, payload, params) + check(res, { + 'POST - update: status is 201': (r) => r.status === 201, + 'POST - update: verify body': (r) => r.body.includes('update') + }) + + sleep(SLEEP_TIME) // second }) } diff --git a/backend/wrangler.toml b/backend/wrangler.toml index 4f06772..5abadfc 100644 --- a/backend/wrangler.toml +++ b/backend/wrangler.toml @@ -7,8 +7,12 @@ r2_buckets = [ { binding = "BLOG_BUCKET", bucket_name = "flinnlab-blog-dev", preview_bucket_name = "flinnlab-blog-dev"} ] +d1_databases = [ + { binding = "DB_DRIP", database_name = "blog-drip-dev", database_id = "d898dfc0-f641-425c-8c6a-e25da2cf7468", migrations_dir = "../data/drip-db/migrations" } +] + [vars] -FLAG_USE_HEADERS=true +#FLAG_USE_HEADERS=true [dev] ip = "0.0.0.0" @@ -25,11 +29,11 @@ r2_buckets = [ { binding = "BLOG_BUCKET", bucket_name = "flinnlab-blog-dev" } ] d1_databases = [ - { binding = "DB", database_name = "blog-drip-dev", database_id = "d898dfc0-f641-425c-8c6a-e25da2cf7468", migrations_dir = "../data/drip-db/migrations" } + { binding = "DB_DRIP", database_name = "blog-drip-dev", database_id = "d898dfc0-f641-425c-8c6a-e25da2cf7468", migrations_dir = "../data/drip-db/migrations" } ] [env.staging.vars] -FLAG_USE_HEADERS=true +#FLAG_USE_HEADERS=true [env.production] @@ -40,8 +44,8 @@ r2_buckets = [ { binding = "BLOG_BUCKET", bucket_name = "flinnlab-blog" } ] d1_databases = [ - { binding = "DB", database_name = "blog-drip", database_id = "b8dc883c-78e0-4687-bfe2-45401ae32813", migrations_dir = "../data/databases/blog-drip/migrations" } + { binding = "DB_DRIP", database_name = "blog-drip", database_id = "b8dc883c-78e0-4687-bfe2-45401ae32813", migrations_dir = "../data/databases/blog-drip/migrations" } ] [env.production.vars] -FLAG_USE_HEADERS=true +#FLAG_USE_HEADERS=true diff --git a/data/tools/edda/src/utils.py b/data/tools/edda/src/utils.py index 641388c..627d721 100644 --- a/data/tools/edda/src/utils.py +++ b/data/tools/edda/src/utils.py @@ -243,7 +243,7 @@ def get_status(env, env_db, migration_table) -> Migrations: results, results_code = execute_sql(sql, env, env_db) if results_code == 1: - return [] + return Migrations('remote', []) return Migrations( "remote", diff --git a/shell.nix b/shell.nix index 091aeaa..e343284 100644 --- a/shell.nix +++ b/shell.nix @@ -13,6 +13,6 @@ in pkgs.mkShell { ]; shellHook = '' - export PATH="$PWD/frontend/node_modules/.bin/:$PWD/backend/node_modules/.bin/:$PATH" + export PATH="$PWD/frontend/node_modules/.bin/:$PWD/backend/node_modules/.bin/:$PWD/data/tools/edda/result/bin:$PATH" ''; }