Sithu (Server Side Rendering)
Simple, Fast and Secure
npm install --save sithu
Special Announcements
Since version 1.1.5, compression mode and cache features are built-in. And infinity sockets mode is default. HSTS with 60 days is supported by default. Build Secure and High Speed
Sample-Tutorial
After installing, build your project structure.
/interceptors /indexjs/pages /indexpug/staticserverjsroutesjspackagejson
In server.js
let Sithu = ;let routes = ; let sithuServer = sithuServer;sithuServer;sithuServer
In pages/index.pug
h1 Hello World from #{name}
In interceptors/index.js
module{ let data = name:'SiThu Server' ;}
In routes.js
let IndexInterceptor = ; moduleexports = "url":"/" "view":"index" interceptor:IndexInterceptor
Then in command line,
node server.js
Open localhost:4200
Api-Documentation
ServerBuilder
let Sithu = require("sithu");
let sithuServer = Sithu(options)
Options can be
hsts, default is true
cache, default is false,
compressionMode, default is false,
view_engine, default is "pug"
Server-class
setRoutes(routes)
setRoutes is method for setting server routes. A typical server route is
url:"/" view:"index" interceptor:indexInterceptor
listen(port,callback[options])
Default port is 4200. Callback is optional.
server;
setViewEngine(engineName)
setViewEngine is a method for setting view engine in sithu.js. Default is pug view engine. Customize engine requires npm installation. If you need ejs,
npm install ejs
server;
addLogger()
addLogger is a method for setting log files in your app. This is a good-to-have feature in production mode.
server; //call method before deployserver;
In your working directory, server.log file is automatically created.
deploy()
If the server is ready to deploy, this method should be called.
ifprocessenvNODE_ENV =="production" server
Interceptor
interceptor function receives three arguments.
module{ ifcontextheadersauthorization == "true" response; //redirecting ; //to render view }
Fetching
Fetching can be used in interceptors. These are powerful part of sithu framework and makes it UI server.
// in interceptorlet fetcher = ; moduleexports = asynccotextresponsenext let ajaxRes = await ; let data = await ajaxRes;
Fetcher library of sithu is based on isomorphic-unfetch library.