Skip to content

Releases: GamanJS/gaman

v1.2.8

21 Oct 09:03

Choose a tag to compare

What's Changed

Full Changelog: v1.2.7...v1.2.8

v1.2.7

21 Oct 08:55

Choose a tag to compare

What's Changed

Full Changelog: v1.2.6...v1.2.7

v1.2.6

21 Oct 08:36

Choose a tag to compare

What's Changed

Full Changelog: v1.2.5...v1.2.6

v1.2.5

18 Oct 22:37

Choose a tag to compare

What's Changed

Read New Documentations

https://gaman.7togk.id/docs

New Contributors

Full Changelog: v1.2.4...v1.2.5

v1.2.4

05 Oct 16:50

Choose a tag to compare

What's Changed

Full Changelog: v1.2.3...v1.2.4

@gaman/[email protected]

11 Oct 15:27

Choose a tag to compare

@gaman/rate-limit

is the official middleware for GamanJS that limits the number of requests from clients within a specified time period.
This plugin is designed to protect applications from request spam, brute-force attacks, and overload, while maintaining stable server performance.

Installation

npm install @gaman/rate-limit

Basic

import { rateLimit } from '@gaman/rate-limit';

defineBootstrap(async (app) => {
  app.mount(
    rateLimit({
      ttl: 60_000, // 60 detik
      limit: 5, // 5 klien dalam 60 detik
    }),
  );
});

Docs: https://gaman.7togk.id/docs/security/rate-limit/
Full Changelog: https://github.com/7TogkID/gaman/compare/@gaman/[email protected]...@gaman/[email protected]

v1.2.3

22 Sep 20:04

Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v1.0.12...v1.2.3

@gaman/[email protected]

22 Sep 19:47

Choose a tag to compare

What's Changed

@gaman/[email protected]

22 Sep 19:44

Choose a tag to compare

What's @gaman/session

@gaman/session is a session middleware for GamanJS.
It helps you manage user sessions using cookies and optional external stores.
You can easily configure session options like cookie name, lifetime, security, and whether it should work in cross-site requests.

Use this package if you need authentication, persistent login, or simple state management between requests.

Installation

npm i @gaman/session

Basic Implementation

// index.ts
import { session } from "@gaman/session"

defineBootstrap((app) => {

   app.mount(
     session({
        crossSite: false // if you want 2 applications such as Vite React + GamanJS, crossSite: make it true
     })
   )
});
// Handler.ts
(ctx) => {
  ctx.session.set({userId: '...'});
  
  ctx.session.get();
  ctx.session.delete();
}

Cross Site

if you want cross site you need additional plugins namely @gaman/cors type npm i @gaman/cors to install

// index.ts
import { session } from "@gaman/session"
import { cors } from "@gaman/cors"

defineBootstrap((app) => {

   app.mount(
     cors({
       origin: ['http://localhost:3000'] // set client app url,
       credentials: true // must be true
     }),
     session({
        crossSite: true //<- set true
     })
   )
});

create route /login

route.post('/login', (ctx) => {

   ctx.session.set({ userId: 'abogoboga' }); // set session

   return Res.json({message: "OK!"});
});

on the client or in the app vite + react I will give an example using fetch

<script>
  fetch('http://localhost:3431/login', {
    method: "POST",
    credentials: 'include' // must be include
  });

</script>

session will be automatically set to cookies (HTTP ONLY)

Full Changelog: https://github.com/7TogkID/gaman/compare/@gaman/[email protected]...@gaman/[email protected]

@gaman/[email protected]

21 Sep 18:13

Choose a tag to compare

What's @gaman/websocket

@gaman/websocket is a GamanJS module for creating and managing WebSocket connections easily.

Installation

npm i ws @gaman/websocket

# if using typescript
npm i --save-dev @types/ws

Basic Example

initial websocket module

// index.ts
import { WebsocketGateway } from "@gaman/websocket"

defineBootstrap((app) => {
  const server = app.mountServer(':3431');
  WebsocketGateway.upgrade(server);
})

create websocket handler

// ChatWebsocket.ts
import { composeWebsocket } from "@gaman/websocket"

export default composeWebsocket((event) => {
  Log.info('Client joined: ' + event.clientId);
  
  event.onMessage((msg) => {
    event.send('your message: ' + msg);
  })
})

register websocket handler to routes

// AppRoutes.ts
export default autoComposeRoutes((route) => {
  route.ws('/chat', ChatWebsocket);
});

and then connect to ws://localhost:3431/chat
if you using wscat use this command wscat -c ws://localhost:3431/chat and then type message and enter

Websocket Middleware

create message middleware handler

// ChatWebsocketMiddleware.ts
import { composeWebsocketMiddleware } from "@gaman/websocket"

export default composeWebsocketMiddleware((event, next) => {
  if(event.message === 'bruh'){
     event.send('Badword character')
  }
  next();
})

register to your route

// AppRoutes.ts
export default autoComposeRoutes((route) => {
  route.ws('/chat', ChatWebsocket).middleware(ChatWebsocketMiddleware());
});

Full Changelog: https://github.com/7TogkID/gaman/compare/@gaman/[email protected]...@gaman/[email protected]