Releases: GamanJS/gaman
v1.2.8
What's Changed
- fix autoCompose dirs not found by @angga7togk in f248577
Full Changelog: v1.2.7...v1.2.8
v1.2.7
What's Changed
- add
globdependencies for@gaman/cliby @angga7togk in d0ebf2e
Full Changelog: v1.2.6...v1.2.7
v1.2.6
What's Changed
- Feat/builder add new builder for static file by @angga7togk in #36
Full Changelog: v1.2.5...v1.2.6
v1.2.5
What's Changed
- add @gaman/edge view engine plugins by @angga7togk in #32
- add @gaman/jwt plugin and routes by @fiandev in #33
- add
composeServicefor bussines logic by @angga7togk in 20fb258 - add
autoComposeDirsconfig forgaman.config.mjsby @angga7togk in 20fb258 - using gamanjs now at least use nodejs >= 20.x
Read New Documentations
New Contributors
Full Changelog: v1.2.4...v1.2.5
v1.2.4
What's Changed
- add
composeStoregeneric by @angga7togk in 9bb1d45 - add @gaman/rate-limit plugins for gamanjs by @angga7togk in #30
- add store and onReceive options in @gaman/rate-limit by @angga7togk in #31
Full Changelog: v1.2.3...v1.2.4
@gaman/[email protected]
@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-limitBasic
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
What's Changed
- add new plugins @gaman/websocket by @angga7togk in release
- Refactor WebsocketAdapter by @Mipan-Zuzu in #23
- add response shorthand methods by @ilsyaa in #25
- add new plugins @gaman/session by @angga7togk in #26
- add shorthand status response by @angga7togk in 57c561a
New Contributors
- @Mipan-Zuzu made their first contribution in #23
- @ilsyaa made their first contribution in #25
Full Changelog: v1.0.12...v1.2.3
@gaman/[email protected]
What's Changed
- Refactor WebsocketAdapter: #23 Thanks for @Mipan-Zuzu
@gaman/[email protected]
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/sessionBasic 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]
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/wsBasic 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]