Skip to content

Commit

Permalink
added rate limit error
Browse files Browse the repository at this point in the history
  • Loading branch information
darienmiller88 committed Aug 29, 2023
1 parent d4ef463 commit 96767cc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
12 changes: 12 additions & 0 deletions client2/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@
let name: string = ""
let tweedContent: string = ""
let tweeds: Tweed[] = []
let isAtBottom: boolean = false
let finished: boolean = false
let skip: number = 0
let limit: number = 5
let isRateLimited: boolean = false
let rateLimitError: string = "Stop sending so much fucking tweeds!"
let URL: string = window.location.hostname == "localhost" ? "http://localhost:8080/api/v1/tweeds" : "https://twidderapi.fly.dev/api/v1/tweeds"
$: if(isAtBottom && !finished){
(async () => {
Expand Down Expand Up @@ -52,6 +57,7 @@
tweeds = [tweed, ...tweeds]
isLoading = false
} catch (error) {
error.message
console.log("err:", error)
}
Expand Down Expand Up @@ -99,6 +105,12 @@
<button>Send Tweed!</button>
</form>

{#if isRateLimited}
<div class="rate-limit-error">
{rateLimitError}
</div>
{/if}

{#if isLoading}
<div class="loading">
<Moon size="200" color="#1DA1F2" unit="px" duration="0.75s" />
Expand Down
11 changes: 11 additions & 0 deletions client2/src/tweed.scss
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,15 @@ form{
color: var(--twidder-blue);
font-size: 20px;
text-align: center;
}

.rate-limit-error{
background-color: rgb(170, 50, 40);
color: white;

border-radius: 5px;
padding: 20px;
width: 70%;
margin: auto;
margin-top: 20px;
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func main(){
app.Use(cors.New())
app.Use(logger.New())
app.Use(limiter.New(limiter.Config{
Max: 2000,
Max: 30,
Expiration: 24 * time.Hour,
LimitReached: func(c *fiber.Ctx) error {
return c.Status(http.StatusBadRequest).JSON(fiber.Map{
Expand Down
Binary file modified tmp/runner-build.exe
Binary file not shown.
Binary file modified tmp/runner-build.exe~
Binary file not shown.

0 comments on commit 96767cc

Please sign in to comment.