basic functionality

This commit is contained in:
Christine Dodrill 2016-02-06 07:54:55 -08:00
parent ccc1bbe59b
commit 5a6bab4a12
5 changed files with 75 additions and 3 deletions

View File

@ -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>

View File

@ -1 +1,2 @@
--define:ssl --define:ssl
--threads:on

61
src/twtxtlist.nim Normal file
View File

@ -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()

0
src/twtxtlist.nims Normal file
View File

View File

@ -9,12 +9,13 @@ bin = @["twtxtlist"]
# Dependencies # Dependencies
requires "nim >= 0.13.0" requires "nim >= 0.13.0", "jester", "moustachu", "shorturl"
mode = ScriptMode.Verbose mode = ScriptMode.Verbose
task db, "SQLite database prompt": task db, "SQLite database prompt":
exec "sqlite3 data/twtxt.db" exec "sqlite3 data/twtxt.db"
task migrate, "Run database migrations": task run, "Run app":
exec "sqlite3 data/twtxt.db" exec "nimble build"
exec "./twtxtlist"