diff --git a/src/templates/error.mustache b/src/templates/error.mustache
new file mode 100644
index 0000000..d8f2023
--- /dev/null
+++ b/src/templates/error.mustache
@@ -0,0 +1,9 @@
+
+
+ could not find that page. are you sure you clicked on a valid link?
+
+
+
+{{ exception }}
+
+
diff --git a/src/twtxt.nims b/src/twtxt.nims
index fc86e83..96c7687 100644
--- a/src/twtxt.nims
+++ b/src/twtxt.nims
@@ -1 +1,2 @@
--define:ssl
+--threads:on
diff --git a/src/twtxtlist.nim b/src/twtxtlist.nim
new file mode 100644
index 0000000..760023a
--- /dev/null
+++ b/src/twtxtlist.nim
@@ -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()
diff --git a/src/twtxtlist.nims b/src/twtxtlist.nims
new file mode 100644
index 0000000..e69de29
diff --git a/twtxtlist.nimble b/twtxtlist.nimble
index 6853779..33d4b40 100644
--- a/twtxtlist.nimble
+++ b/twtxtlist.nimble
@@ -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"