Developing an App with Flitter

Part I — Getting Started

What are we building?

1. Getting Set Up

1.1 — Prerequisites

1.2 — Grab a copy of Flitter.

$ git clone https://git.glmdev.tech/flitter/flitter todo-app
$ cd todo-app/
$ yarn install

1.3 — Configure the Environment

SERVER_PORT=8000
LOGGING_LEVEL=1
DATABASE_HOST=127.0.0.1
DATABASE_PORT=27017
DATABASE_NAME=flitter
DATABASE_AUTH=true
DATABASE_USER=flitter
DATABASE_PASS=flitter
SECRET=changemetosomethingrandom
ENVIRONMENT=development
$ ./flitter test
Flitter launched successfully. That doesn't mean that all of your app logic works, just that the framework backend initialized properly.

2. Create the User Auth

$ ./flitter deploy auth

2.1 — Test it out!

$ ./flitter up
Flitter running on port 8000! Press ^C to exit cleanly.
The default Flitter registration page.

3. First Looks

3.1 — Routing

module.exports = exports = {
prefix: '/auth',

get: {
'/register': [ _flitter.mw('auth:RequireGuest'),
_flitter.controller('Auth').register_get ],
'/login': [ _flitter.mw('auth:RequireGuest'),
_flitter.controller('Auth').login_get ],
'/logout': [ _flitter.mw('auth:RequireAuth'),
_flitter.controller('Auth').logout ],

'/dash': [ _flitter.mw('auth:RequireAuth'),
_flitter.controller('Auth').dash_get ]
},

post: {
'/register': [ _flitter.mw('auth:RequireGuest'),
_flitter.controller('Auth').register_post ],
'/login': [ _flitter.mw('auth:RequireGuest'),
_flitter.controller('Auth').login_post ],
},
}

3.2 — Middleware

figure 3.2a: A simplified diagram of an MVC request/response flow.
class RequireGuest {
test(req, res, next){
if ( req.session && req.session.auth &&
(req.session.auth.authenticated === true ||
req.session.auth.user) ){

return _flitter.view(res, 'errors/requires_guest')
}
next()
}
}

module.exports = RequireGuest

3.3 — Controllers

const validator = require('validator')
const bcrypt = require('bcrypt')
const uuid = require('uuid/v4')

class Auth {
// ... other methods omitted ... dash_get(req, res, handle_error){
return _flitter.view(res, 'auth/dash',
{ user: req.session.auth.user })
}
}

module.exports = Auth

3.4 — Database Models

module.exports = exports = {
username: String,
password: String,
data: String,
uuid: String,
}

3.5 — Static Assets & Views

const validator = require('validator')
const bcrypt = require('bcrypt')
const uuid = require('uuid/v4')

class Auth {
// ... other methods omitted ...dash_get(req, res, handle_error){
return _flitter.view(res, 'auth/dash',
{ user: req.session.auth.user })
}
}

module.exports = Auth

Part I Conclusion

Hi, there. I’m a software developer and speaker who likes to make things: https://garrettmills.dev/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store