import Application from require "lapis" import APIKeys, Tasks from require "models" import autoload, locate, registry from require "locator" import settings from autoload "utility" import main from autoload "layouts" class Simplex extends Application @before_filter => settings.load! registry.before_filter(@) layout: main @include locate "users" @include locate "api" @include locate "docs" handle_error: (err, trace) => if @original_request.route_name\find "api_" -- return status: 500, json: { errors: {err}, :trace } -- NOTE trace should be saved and NOT returned to the user return status: 500, json: { errors: {err} } else super err --, trace [index: "/"]: => if @user @keys = APIKeys\select "WHERE user_id = ? ORDER BY id ASC", @user.id @tasks = Tasks\select "WHERE user_id = ? ORDER BY id ASC", @user.id unless @keys and #@keys > 0 @keys = {APIKeys\create(@user)} return render: "index.logged_in" else return render: "index.logged_out" [console: "/console"]: => if @user and @user.admin console = require "lapis.console" return console.make(env: "all")(@) else return status: 404, "Not found."