Initial commit

This commit is contained in:
2020-10-05 11:44:05 -05:00
commit 5917935505
29 changed files with 385 additions and 0 deletions

2
app/assets/.gitkeep Normal file
View File

@@ -0,0 +1,2 @@
*
!.gitignore

27
app/configs/app.config.ts Normal file
View File

@@ -0,0 +1,27 @@
import { Daton } from '../../bundle/daton.ts'
const { env, ViewEngine } = Daton
export default {
name: env('APP_NAME', 'Daton'),
views: {
/*
* View engine that should be used to render templates.
* Options are Handlebars, Ejs, or Denjuck.
*/
engine: ViewEngine.Handlebars,
/*
* Relative path from the app directory to the base directory where
* view files should be looked up.
*/
base_dir: 'http/views',
/*
* If using Handlebars, optionally, the path to the directory within the
* base_dir that contains the partials. They will be automatically registered
* with Handlebars.
*/
partials_dir: 'partials',
},
}

17
app/configs/db.config.ts Normal file
View File

@@ -0,0 +1,17 @@
import { Daton } from '../../bundle/daton.ts'
const { env } = Daton
export default {
connections: {
default: {
type: env('DB_TYPE', 'postgres'),
user: env('DB_USERNAME', 'daton'),
password: env('DB_PASSWORD'),
database: env('DB_DATABASE', 'daton'),
hostname: env('DB_HOSTNAME', 'localhost'),
port: env('DB_PORT', 5432),
}
}
}

View File

@@ -0,0 +1,18 @@
export default {
port: 8080,
use_ssl: false,
prefix: '/',
allow_mount_without_prefix: false,
request_timeout: 15000, // 15 seconds
powered_by: {
enable: true,
text: 'Daton',
},
session: {
driver: 'database', // memory | database
model: 'http:Session', // required for database
},
}

View File

@@ -0,0 +1,10 @@
import {Controller, Request, view, Injectable} from '../../../bundle/daton.ts'
@Injectable()
export default class HomeController extends Controller {
async get_home(request: Request) {
return view('home', { greeting: 'Hello' })
}
}

View File

@@ -0,0 +1,9 @@
import { Middleware, Request, http, HTTPStatus } from '../../../bundle/daton.ts'
export default class TestMiddleware extends Middleware {
public async handleRequest(request: Request) {
if ( Math.random() >= 0.5 ) {
return http(HTTPStatus.FORBIDDEN, 'Well, you were unlucky.')
}
}
}

View File

@@ -0,0 +1,11 @@
import { RouterDefinition } from '../../../bundle/daton.ts'
export default {
prefix: '/',
middleware: [],
get: {
'/': 'controller::Home.get_home',
'/maybe': ['middleware::Test', 'controller::Home.get_home'],
'/statics/**': { handler: 'daton::static', arg: 'assets' },
},
} as RouterDefinition

9
app/http/views/home.hbs Normal file
View File

@@ -0,0 +1,9 @@
<html>
{{> header }}
<body>
<div class="container">
<h1>Welcome to Daton</h1>
<h2>Daton is an opinionated application framework for Deno</h2>
</div>
</body>
</html>

View File

@@ -0,0 +1,37 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Daton</title>
<link href="https://fonts.googleapis.com/css?family=Quicksand:300,500" rel="stylesheet">
<style>
html, body {
background-color: #F2F4FF;
color: #36453B;
font-family: 'Quicksand', sans-serif;
font-weight: 500;
height: 100vh;
margin: 0;
}
.container {
height: 100vh;
margin: 0;
overflow: hidden;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.container h1 {
margin-bottom: 0;
}
.container h2 {
font-weight: 300;
}
</style>
</head>

View File

@@ -0,0 +1,24 @@
import { Model, Type, Field, Relation } from '../../bundle/daton_orm.ts'
import User from "./User.model.ts";
export default class LoginAttempt extends Model<LoginAttempt> {
protected static table = 'daton_login_attempts'
protected static key = 'daton_login_attempt_id'
protected static readonly CREATED_AT = 'attempt_date'
protected static readonly UPDATED_AT = null
@Field(Type.int)
protected daton_login_attempt_id?: number
@Field(Type.int)
protected user_id!: number
@Field(Type.timestamp)
protected attempt_date!: Date
@Relation()
public user() {
return this.belongs_to_one(User, 'login_attempts')
}
}

27
app/models/User.model.ts Normal file
View File

@@ -0,0 +1,27 @@
import { Model, Type, Field, Relation } from '../../bundle/daton_orm.ts'
import LoginAttemptModel from './LoginAttempt.model.ts'
export default class User extends Model<User> {
protected static table = 'daton_users'
protected static key = 'user_id'
protected static readonly CREATED_AT = 'created_at'
protected static readonly UPDATED_AT = 'updated_at'
@Field(Type.int)
protected user_id?: number
@Field(Type.varchar)
protected first_name!: String
@Field(Type.varchar)
protected last_name!: String
@Field(Type.bool)
protected active!: Boolean
@Relation()
public login_attempts() {
return this.has_many(LoginAttemptModel)
}
}

View File

@@ -0,0 +1,19 @@
import { SessionModel } from '../../../bundle/daton.ts'
import { Field, Type } from '../../../bundle/daton_orm.ts'
export default class Session extends SessionModel {
protected static table = 'sessions'
protected static key = 'session_key'
protected static readonly CREATED_AT = 'start_time'
protected static readonly UPDATED_AT = null // No updated at
@Field(Type.varchar)
protected session_key!: string
@Field(Type.int)
protected user_id?: number
@Field(Type.timestamp)
protected start_time!: Date
}

0
app/services/.gitkeep Normal file
View File