Skip to content

Commit

Permalink
rate limiting (#11)
Browse files Browse the repository at this point in the history
* rate limit for api routes
* lucia auth
  • Loading branch information
haffi96 authored Dec 7, 2023
1 parent a21e8c7 commit ed3664f
Show file tree
Hide file tree
Showing 40 changed files with 3,228 additions and 3,750 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup Node.js environment
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18
cache: "npm"
Expand Down
3 changes: 1 addition & 2 deletions astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import tailwind from "@astrojs/tailwind";
import preact from "@astrojs/preact";
import vercel from "@astrojs/vercel/serverless";

import auth from "auth-astro";

// https://astro.build/config
export default defineConfig({
Expand All @@ -16,5 +15,5 @@ export default defineConfig({
},
integrations: [tailwind(), preact({
compat: true
}), auth()],
})],
});
15 changes: 0 additions & 15 deletions auth.config

This file was deleted.

4,888 changes: 2,448 additions & 2,440 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,29 @@
"generate-migration": "npx drizzle-kit generate:pg --config src/aws/backend/db/config.ts",
"migrate": "npx ts-node src/aws/backend/db/migrate.ts",
"db-push": "npx drizzle-kit push:pg --config src/aws/backend/db/config.ts",
"db-studio": "npx drizzle-kit studio --config src/aws/backend/db/config.ts --port 5000"
"db-studio": "npx drizzle-kit studio --config src/aws/backend/db/config.ts --port 5000",
"test-query": "npx ts-node src/aws/backend/db/query.ts"
},
"dependencies": {
"@astrojs/check": "^0.3.1",
"@astrojs/preact": "^3.0.0",
"@astrojs/tailwind": "^5.0.0",
"@astrojs/vercel": "^5.0.0",
"@auth/core": "^0.5.1",
"@astrojs/ts-plugin": "^1.3.1",
"@astrojs/vercel": "^5.2.0",
"@aws-sdk/client-sqs": "^3.414.0",
"@lucia-auth/adapter-postgresql": "^2.0.2",
"@lucia-auth/oauth": "^3.5.0",
"@types/source-map-support": "^0.5.7",
"@upstash/ratelimit": "^1.0.0",
"@upstash/redis": "^1.25.1",
"@vercel/analytics": "^1.1.1",
"astro": "^3.0.7",
"auth-astro": "^3.0.1",
"aws-cdk-lib": "2.94.0",
"constructs": "^10.0.0",
"dotenv": "^16.3.1",
"drizzle-kit": "^0.19.13",
"drizzle-orm": "^0.28.5",
"lucia": "^2.7.4",
"pg": "^8.11.3",
"postgres": "^3.3.5",
"preact": "^10.6.5",
Expand All @@ -55,6 +61,6 @@
"prettier-plugin-astro": "^0.12.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
"typescript": "^5.3.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ CREATE TABLE IF NOT EXISTS "all_blogs" (
"id" serial PRIMARY KEY NOT NULL,
"blog_uuid" uuid DEFAULT extensions.uuid_generate_v4() NOT NULL,
"link" varchar(256),
"https_link" varchar(256),
"company" varchar(256),
"rss_version" varchar(256)
);
Expand All @@ -10,48 +11,76 @@ CREATE TABLE IF NOT EXISTS "blog_posts" (
"id" serial PRIMARY KEY NOT NULL,
"post_uuid" uuid DEFAULT extensions.uuid_generate_v4() NOT NULL,
"title" varchar(256),
"title_hash" varchar(256) NOT NULL,
"link" varchar(256),
"author" varchar(256),
"published_date" timestamp,
"blog_id" integer
"blog_id" integer,
CONSTRAINT "blog_posts_title_hash_unique" UNIQUE("title_hash")
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "user_key" (
"id" varchar(255) PRIMARY KEY NOT NULL,
"user_id" varchar(15) NOT NULL,
"hashed_password" varchar(255)
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "user_session" (
"id" varchar(128) PRIMARY KEY NOT NULL,
"user_id" varchar(15) NOT NULL,
"active_expires" bigint NOT NULL,
"idle_expires" bigint NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "user_blogs" (
"id" serial PRIMARY KEY NOT NULL,
"user_id" integer,
"user_id" varchar(15) NOT NULL,
"blog_id" integer
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "user_posts" (
"id" serial PRIMARY KEY NOT NULL,
"user_id" integer,
"user_id" varchar(15) NOT NULL,
"post_id" integer,
"emailed" boolean DEFAULT false NOT NULL,
"notification_date" timestamp DEFAULT TIMEZONE('utc', CURRENT_TIMESTAMP) NOT NULL,
"updated_at" timestamp
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "users" (
"id" serial PRIMARY KEY NOT NULL,
CREATE TABLE IF NOT EXISTS "auth_user" (
"id" varchar(15) PRIMARY KEY NOT NULL,
"user_uuid" uuid DEFAULT extensions.uuid_generate_v4() NOT NULL,
"username" varchar(256),
"email" varchar(256)
"username" varchar(256) NOT NULL,
"email" varchar(256),
"email_preference" boolean DEFAULT false NOT NULL,
"provider" varchar(256)
);
--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "uuid_idx" ON "all_blogs" ("blog_uuid");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "uuid_idx" ON "blog_posts" ("post_uuid");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "user_blog_idx" ON "user_blogs" ("user_id","blog_id");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "username_idx" ON "users" ("username");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "email_idx" ON "users" ("email");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "uuid_idx" ON "users" ("user_uuid");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "email_idx" ON "auth_user" ("email");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "uuid_idx" ON "auth_user" ("user_uuid");--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "blog_posts" ADD CONSTRAINT "blog_posts_blog_id_all_blogs_id_fk" FOREIGN KEY ("blog_id") REFERENCES "all_blogs"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "user_blogs" ADD CONSTRAINT "user_blogs_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE no action ON UPDATE no action;
ALTER TABLE "user_key" ADD CONSTRAINT "user_key_user_id_auth_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "auth_user"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "user_session" ADD CONSTRAINT "user_session_user_id_auth_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "auth_user"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "user_blogs" ADD CONSTRAINT "user_blogs_user_id_auth_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "auth_user"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
Expand All @@ -63,7 +92,7 @@ EXCEPTION
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "user_posts" ADD CONSTRAINT "user_posts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE no action ON UPDATE no action;
ALTER TABLE "user_posts" ADD CONSTRAINT "user_posts_user_id_auth_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "auth_user"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
Expand Down
2 changes: 0 additions & 2 deletions src/aws/backend/db/migrations/0001_brave_zemo.sql

This file was deleted.

1 change: 0 additions & 1 deletion src/aws/backend/db/migrations/0002_wandering_daredevil.sql

This file was deleted.

1 change: 0 additions & 1 deletion src/aws/backend/db/migrations/0003_clever_slapstick.sql

This file was deleted.

Loading

0 comments on commit ed3664f

Please sign in to comment.