Tuesday, November 12, 2024

Multi-tenant SaaS (Notes web application) in 200 lines of code

This is a complete SaaS example (Software-as-a-Service) using PostgreSQL as a database, and Gliimly as a web service engine; it includes user signup/login/logout with an email and password, separate user accounts and data, and a notes application. All in about 200 lines of code! Here's a video that shows it - two users sign up and create their own notes:

First create a directory for your application, where the source code will be:
mkdir -p notes
cd notes

Setup Postgres database
Create PostgreSQL user (with the same name as your logged on Linux user, so no password needed), and the database "db_app":
echo "create user $(whoami);
create database db_app with owner=$(whoami);
grant all on database db_app to $(whoami);
\q"  | sudo -u postgres psql

Create a database configuration file to describe your PostgreSQL database above:
echo "user=$(whoami) dbname=db_app" > db_app

Create database objects we'll need - users table for application users, and notes table to hold their notes:
echo "create table if not exists notes (dateOf timestamp, noteId bigserial primary key, userId bigint, note varchar(1000));
create table if not exists users (userId bigserial primary key, email varchar(100), hashed_pwd varchar(100), verified smallint, verify_token varchar(30), session varchar(100));
create unique index if not exists users1 on users (email);" | psql -d db_app

Create Gliimly application
Create application "notes" owned by your Linux user:
sudo mgrg -i -u $(whoami) notes

Source code
This executes before any other handler in an application, making sure all requests are authorized, file "before-handler.gliim":
vi before-handler.gliim

 before-handler
     set-param displayed_logout = false, is_logged_in = false
     call-handler "/session/check"
 end-before-handler


- Signup users, login, logout

This is a generic session management web service that handles user creation, verification, login and logout. Create file "session.gliim":

Sunday, November 10, 2024

Gliimly 91 released

  • Fixed SELinux installation bug for Fedora-like distros.
  • Minimum number of CPUs available is 1 in case there's an issue in determining the number of them.
  • Fixed issue with highlighting call-handler statement in vim.

Tuesday, November 5, 2024

Gliimly 87 released

  • Added --exclude option to gg in order to exclude sub-directories from compilation.
  • Added p-source-line and p-source-file statements to aid in debugging.
  • A request handler can now be defined in any source file whose path matches, partially or fully, the request path of the handler. For instance /session/login request handler can be defined either in file "session.gliim" or "session/login.gliim". A source file can also have multiple request handlers that match path.
  • Added --single-file option to gg to force each source code file to have just a single request handler.
  • set-param and get-param statements now work with multiple parameters separated by a comma.
  • set-cookie and get-cookie statements now work with multiple cookies separated by a comma.
  • Fixed bug in end-write-string statement where junk text at the end would be ignored without an error message.
  • Fixed error in parallel compilation.
  • Fixed bug in get-param where parameter name wouldn't be correct.
  • Fixed bug where a function in call-extended statement wouldn't work without any parameters.