1
1
import type { Model , Options , Route , RouteParam , ServeOptions } from '@stacksjs/types'
2
- import type { RateLimitResult } from 'ts-rate-limiter'
2
+ // import type { RateLimitResult } from 'ts-rate-limiter'
3
3
4
4
import process from 'node:process'
5
5
import { handleError } from '@stacksjs/error-handling'
@@ -8,30 +8,30 @@ import { getModelName } from '@stacksjs/orm'
8
8
import { extname , path } from '@stacksjs/path'
9
9
import { fs , globSync } from '@stacksjs/storage'
10
10
import { isNumber } from '@stacksjs/validation'
11
- import { RateLimiter } from 'ts-rate-limiter'
11
+ // import { RateLimiter } from 'ts-rate-limiter'
12
12
import { route , staticRoute } from '.'
13
13
14
14
import { middlewares } from './middleware'
15
15
16
16
import { request as RequestParam } from './request'
17
17
18
- const limiter = new RateLimiter ( {
19
- windowMs : 15 * 60 * 1000 , // 15 minutes
20
- maxRequests : 100 ,
21
- algorithm : 'sliding-window' ,
22
- handler : ( req : Request , result : RateLimitResult ) => {
23
- return new Response ( JSON . stringify ( {
24
- error : 'Too many requests' ,
25
- retryAfter : Math . ceil ( result . remaining / 1000 ) ,
26
- } ) , {
27
- status : 429 ,
28
- headers : {
29
- 'Content-Type' : 'application/json' ,
30
- 'Retry-After' : Math . ceil ( result . remaining / 1000 ) . toString ( ) ,
31
- } ,
32
- } )
33
- } ,
34
- } )
18
+ // const limiter = new RateLimiter({
19
+ // windowMs: 15 * 60 * 1000, // 15 minutes
20
+ // maxRequests: 100,
21
+ // algorithm: 'sliding-window',
22
+ // handler: (req: Request, result: RateLimitResult) => {
23
+ // return new Response(JSON.stringify({
24
+ // error: 'Too many requests',
25
+ // retryAfter: Math.ceil(result.remaining / 1000),
26
+ // }), {
27
+ // status: 429,
28
+ // headers: {
29
+ // 'Content-Type': 'application/json',
30
+ // 'Retry-After': Math.ceil(result.remaining / 1000).toString(),
31
+ // },
32
+ // })
33
+ // },
34
+ // })
35
35
36
36
export async function serve ( options : ServeOptions = { } ) : Promise < void > {
37
37
const hostname = options . host || 'localhost'
@@ -61,15 +61,15 @@ export async function serverResponse(req: Request, body: string): Promise<Respon
61
61
log . debug ( `Headers: ${ JSON . stringify ( req . headers ) } ` )
62
62
log . debug ( `Body: ${ JSON . stringify ( req . body ) } ` )
63
63
64
- const result = await limiter . check ( req )
64
+ // const result = await limiter.check(req)
65
65
66
- if ( ! result . allowed ) {
67
- log . info ( `Rate limit exceeded: ${ result . current } /${ result . limit } ` )
68
- log . info ( `Reset in ${ Math . ceil ( result . remaining / 1000 ) } seconds` )
66
+ // if (!result.allowed) {
67
+ // log.info(`Rate limit exceeded: ${result.current}/${result.limit}`)
68
+ // log.info(`Reset in ${Math.ceil(result.remaining / 1000)} seconds`)
69
69
70
- // Handle rate limiting in your own way
71
- return new Response ( 'Too many requests' , { status : 429 } )
72
- }
70
+ // // Handle rate limiting in your own way
71
+ // return new Response('Too many requests', { status: 429 })
72
+ // }
73
73
74
74
const trimmedUrl = req . url . endsWith ( '/' ) && req . url . length > 1 ? req . url . slice ( 0 , - 1 ) : req . url
75
75
const url : URL = new URL ( trimmedUrl ) as URL
0 commit comments