Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Commit

Permalink
feat(CI): add the required files
Browse files Browse the repository at this point in the history
  • Loading branch information
meysam81 committed Aug 16, 2024
1 parent fbb30ef commit 0877e96
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 3 deletions.
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "terraform"
directory: "/"
schedule:
interval: "weekly"
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: ci

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}

trivy:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
scan-type:
- fs
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Trivy ${{ matrix.scan-type }}
uses: aquasecurity/trivy-action@master
with:
exit-code: "1"
scan-ref: .
scan-type: ${{ matrix.scan-type }}
trivy-config: trivy.yaml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,4 @@ dist
.wrangler/
worker-local
.envrc
.secrets
26 changes: 23 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,29 @@ export default {

if (method == "POST" && pathname == "/subscribe") {
try {
var subscriber = await request.json();
var subscriber;

if (!subscriber.first_name || !subscriber.email) {
const contentType = request.headers.get("Content-Type");

if (contentType === "application/json") {
subscriber = await request.json();
} else if (contentType === "application/x-www-form-urlencoded") {
const formData = await request.formData();
subscriber = {
first_name: formData.get("first_name"),
email: formData.get("email"),
};
} else {
return new Response(
JSON.stringify({
error: "Unsupported Content-Type",
hint: "Content-Type should be either application/json or application/x-www-form-urlencoded",
}),
{ status: 400 }
);
}

if (!subscriber.email) {
var valid_payload = {
first_name: "John",
email: "[email protected]",
Expand Down Expand Up @@ -155,7 +175,7 @@ async function insertSubscriber(env, subscriber) {
SELECT id, $4
FROM subscriber
`,
[userId, first_name, email, listId]
[userId, first_name || "", email, listId]
);

console.log(insertSubscriber);
Expand Down

0 comments on commit 0877e96

Please sign in to comment.