How to create a session middleware?
We create a session middleware for Total.js application in this blog post. It's easy and useful.

How to create a session middleware?
We create a simple middleware
You can save the code below as your-app/definitions/session.js:
- constant SESSIONcontains all active sessions
- constant TIMEOUTcontains expiration time for a session
- constant COOKIEcontains a cookie name
Usage
Now we can use the middleware, so create/modify a controller e.g. /your-app/controllers/default.js:
What have we done in the code above?
- we created a route to homepage F.route('/', action, [flags])
- the route contains sessionmiddleware, which we created
- then we used controller.sessionin the controller's action
Extend middleware by adding e.g. events
Now it's very easy to extend functionality of middleware. So I extend the code below:
Usage:
You can use the code below in each .js file on the server-side in Total.js.
How to set the middleware to multiple routes together?
- F.use()can sets middleware globally - documentation
- F.groupcreates a group of flags for routes - documentation
Other posts from Total.js Platform
- 2025-10-22New universal drivers for IoT Platform
- 2025-10-13IoT Platform Update: New Features and Enhancements
- 2025-10-01September report 2025
- 2025-09-05How to create Google Gemini AI component in Total.js Flow
- 2025-09-01August report 2025
- 2025-08-25IoT platform — Total.js
- 2025-08-22How to install OpenPlatform — IoT platform
- 2025-08-18Total.js Tables is here!
- 2025-08-18How to install Flow — IoT platform
- 2025-08-15How to install OpenReports — IoT platform
