statikly
No hassle full stack framework, for blog/static/content sites, amazing for prototype and build internal tools and seo optimize.
Provide alternative for writing frontend "the old way", more and more hype is growing on server side ui, like next.js and remix, I wanted to simplified it event more.
statikly is just an opinionated warpper around fastify ecosystem.
when your app is growing you can always eject and control everting yourself.
Installation
npm i -g statikly
Configuration
environment variables:
STATIKLY_SESSION_SECRET=
NODE_ENV=production
STATIKLY_ROOT=
STATIKLY_STATIC_FOLDER=public
STATIKLY_TEMPLATE=ejs
STATIKLY_LAYOUT=
STATIKLY_VIEWS=views
STATIKLY_PASSWORD=1234
STATIKLY_USERNAME=user
defaults:
- template engine ejs
- views folder = views
- api folder = api
- public folder = public
All routes is file base:
views/notes/index.ejs => /notes
views/note/[id].ejs => /note/:id
api/notes/index.js => api/notes
api/note/[id].js => api/note/:id
Getting Started
Start with example app
mkdir my-first-statikly
cd my-first-statikly
statikly init
statikly serve
Manual guide
Write your first view, create views/index.ejs and run statikly serve
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>statikly</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<h1><%= "query" %></h1>
<h3><%= JSON.stringify(query,null,2); %></h3>
<h1><%= "params" %></h1>
<h3><%= JSON.stringify(params,null,2); %></h3>
<h1><%= "data" %></h1>
<h3><%= JSON.stringify(data,null,2); %></h3>
<h1><%= "env" %></h1>
<h3><%= JSON.stringify(env,null,2); %></h3>
</body>
Passing server side data to views, create views/loader.js and run statikly
module.exports = {
loader: async (req, reply) => {
return { todos };
},
};
Processing forms
module.exports = {
actions: async (req, reply) => {
const title = req.body.title;
if (title.length < 2) {
req.flash('errors', ['title length should be longer then 2 characters']);
return reply.redirect('/todos');
}
await db.add(title);
reply.redirect('/todos');
},
};
Api routes, create api/notes.js and run statikly
module.exports = {
get: async (req, reply) => [{ id: 1, title: 'note1' }],
post: async (req, reply) => [{ id: 1, title: 'note1' }],
};
curl http://localhost:3000/api/notes
Build on top of fastify, for more information, checkout the fastify docs
Recommended reading:
TODO:
- advance form support (server/client)
- static gen
- auth / social login / jwt support
- css and js minify / bundler (vite)
- verify security features