basic functionality
This commit is contained in:
parent
ccc1bbe59b
commit
5a6bab4a12
|
@ -0,0 +1,9 @@
|
|||
<div class="error">
|
||||
<center>
|
||||
<p>could not find that page. are you sure you clicked on a valid link?</p>
|
||||
</center>
|
||||
|
||||
<pre>
|
||||
{{ exception }}
|
||||
</pre>
|
||||
</div>
|
|
@ -1 +1,2 @@
|
|||
--define:ssl
|
||||
--threads:on
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
import asyncdispatch, db_sqlite, jester, moustachu, os, shorturl,
|
||||
strutils, tables, times, typetraits
|
||||
|
||||
const
|
||||
baseTemplate*: string = staticRead "./templates/layout.mustache"
|
||||
errorTemplate*: string = staticRead "./templates/error.mustache"
|
||||
|
||||
let
|
||||
db = open("data/twtxt.db", nil, nil, nil)
|
||||
|
||||
try:
|
||||
db.exec sql"""create table if not exists users (
|
||||
id INTEGER PRIMARY KEY,
|
||||
username TEXT UNIQUE,
|
||||
url TEXT UNIQUE
|
||||
);"""
|
||||
|
||||
db.exec sql"""create table if not exists tweets (
|
||||
id INTEGER PRIMARY KEY,
|
||||
username TEXT,
|
||||
time REAL,
|
||||
tweet TEXT,
|
||||
UNIQUE (username, time, tweet)
|
||||
);"""
|
||||
except:
|
||||
quit getCurrentExceptionMsg()
|
||||
|
||||
template renderMustache*(title: string, templ: string, ctx: Context): expr =
|
||||
var
|
||||
layoutCtx = moustachu.newContext()
|
||||
|
||||
layoutCtx["title"] = title
|
||||
layoutCtx["body"] = render(templ, ctx)
|
||||
|
||||
resp render(baseTemplate, layoutCtx)
|
||||
|
||||
template fail*(): expr =
|
||||
var ctx = newContext()
|
||||
|
||||
ctx["exception"] = getCurrentExceptionMsg()
|
||||
|
||||
var
|
||||
layoutCtx = moustachu.newContext()
|
||||
|
||||
layoutCtx["title"] = "fail"
|
||||
layoutCtx["body"] = render(errorTemplate, ctx)
|
||||
|
||||
halt render(baseTemplate, layoutCtx)
|
||||
|
||||
settings:
|
||||
port = getEnv("PORT").parseInt().Port
|
||||
bindAddr = "0.0.0.0"
|
||||
|
||||
routes:
|
||||
get "/":
|
||||
try:
|
||||
raise newException(ValueError, "yolo")
|
||||
except:
|
||||
fail()
|
||||
|
||||
runForever()
|
|
@ -9,12 +9,13 @@ bin = @["twtxtlist"]
|
|||
|
||||
# Dependencies
|
||||
|
||||
requires "nim >= 0.13.0"
|
||||
requires "nim >= 0.13.0", "jester", "moustachu", "shorturl"
|
||||
|
||||
mode = ScriptMode.Verbose
|
||||
|
||||
task db, "SQLite database prompt":
|
||||
exec "sqlite3 data/twtxt.db"
|
||||
|
||||
task migrate, "Run database migrations":
|
||||
exec "sqlite3 data/twtxt.db"
|
||||
task run, "Run app":
|
||||
exec "nimble build"
|
||||
exec "./twtxtlist"
|
||||
|
|
Loading…
Reference in New Issue