2020-11-07 21:46:03 +01:00
|
|
|
import asyncdispatch, strformat
|
2019-07-31 02:15:43 +02:00
|
|
|
from net import Port
|
2019-06-20 16:16:20 +02:00
|
|
|
|
2019-09-06 02:42:35 +02:00
|
|
|
import jester
|
2019-06-24 23:25:21 +02:00
|
|
|
|
2020-11-07 21:31:03 +01:00
|
|
|
import types, config, prefs, formatters, redis_cache, http_pool, tokens
|
2019-09-09 04:41:20 +02:00
|
|
|
import views/[general, about]
|
2019-09-23 16:12:20 +02:00
|
|
|
import routes/[
|
2019-12-30 11:41:09 +01:00
|
|
|
preferences, timeline, status, media, search, rss, list,
|
2020-06-09 16:45:21 +02:00
|
|
|
unsupported, embed, resolver, router_utils]
|
2019-06-20 16:16:20 +02:00
|
|
|
|
2019-07-31 02:15:43 +02:00
|
|
|
const configPath {.strdefine.} = "./nitter.conf"
|
2020-05-08 02:48:47 +02:00
|
|
|
let (cfg, fullCfg) = getConfig(configPath)
|
|
|
|
|
2020-06-09 20:29:05 +02:00
|
|
|
when defined(release):
|
2020-11-07 23:16:33 +01:00
|
|
|
import logging
|
2020-06-09 20:29:05 +02:00
|
|
|
# Silence Jester's query warning
|
|
|
|
addHandler(newConsoleLogger())
|
|
|
|
setLogFilter(lvlError)
|
2020-06-07 09:18:40 +02:00
|
|
|
|
|
|
|
let http = if cfg.useHttps: "https" else: "http"
|
|
|
|
stdout.write &"Starting Nitter at {http}://{cfg.hostname}\n"
|
|
|
|
stdout.flushFile
|
|
|
|
|
2020-05-08 02:48:47 +02:00
|
|
|
updateDefaultPrefs(fullCfg)
|
2020-06-01 02:25:39 +02:00
|
|
|
setCacheTimes(cfg)
|
2019-10-24 00:17:38 +02:00
|
|
|
setHmacKey(cfg.hmacKey)
|
2020-06-09 15:04:38 +02:00
|
|
|
setProxyEncoding(cfg.base64Media)
|
2020-11-07 21:31:03 +01:00
|
|
|
setMaxHttpConns(100)
|
2020-06-01 13:36:10 +02:00
|
|
|
|
2020-06-06 09:27:25 +02:00
|
|
|
waitFor initRedisPool(cfg)
|
2020-06-07 09:18:40 +02:00
|
|
|
stdout.write &"Connected to Redis at {cfg.redisHost}:{cfg.redisPort}\n"
|
|
|
|
stdout.flushFile
|
|
|
|
|
2020-06-01 02:25:39 +02:00
|
|
|
asyncCheck initTokenPool(cfg)
|
2019-10-24 00:17:38 +02:00
|
|
|
|
2019-09-23 16:12:20 +02:00
|
|
|
createUnsupportedRouter(cfg)
|
2019-12-30 11:41:09 +01:00
|
|
|
createResolverRouter(cfg)
|
2019-09-06 02:42:35 +02:00
|
|
|
createPrefRouter(cfg)
|
|
|
|
createTimelineRouter(cfg)
|
2019-09-21 01:08:30 +02:00
|
|
|
createListRouter(cfg)
|
2019-09-20 14:10:10 +02:00
|
|
|
createStatusRouter(cfg)
|
2019-09-13 22:24:58 +02:00
|
|
|
createSearchRouter(cfg)
|
2019-09-06 02:42:35 +02:00
|
|
|
createMediaRouter(cfg)
|
2019-12-06 15:15:56 +01:00
|
|
|
createEmbedRouter(cfg)
|
2019-09-15 12:10:43 +02:00
|
|
|
createRssRouter(cfg)
|
2019-07-31 02:15:43 +02:00
|
|
|
|
|
|
|
settings:
|
|
|
|
port = Port(cfg.port)
|
|
|
|
staticDir = cfg.staticDir
|
|
|
|
bindAddr = cfg.address
|
|
|
|
|
2019-06-20 16:16:20 +02:00
|
|
|
routes:
|
|
|
|
get "/":
|
2020-06-09 16:45:21 +02:00
|
|
|
resp renderMain(renderSearch(), request, cfg, themePrefs())
|
2019-06-20 16:16:20 +02:00
|
|
|
|
2019-09-09 04:41:20 +02:00
|
|
|
get "/about":
|
2020-06-09 16:45:21 +02:00
|
|
|
resp renderMain(renderAbout(), request, cfg, themePrefs())
|
2019-09-09 04:41:20 +02:00
|
|
|
|
2019-09-23 16:12:20 +02:00
|
|
|
get "/explore":
|
|
|
|
redirect("/about")
|
2019-09-23 01:55:02 +02:00
|
|
|
|
2019-09-23 16:12:20 +02:00
|
|
|
get "/help":
|
|
|
|
redirect("/about")
|
|
|
|
|
2019-10-18 00:45:54 +02:00
|
|
|
get "/i/redirect":
|
|
|
|
let url = decodeUrl(@"url")
|
2019-10-21 07:59:22 +02:00
|
|
|
if url.len == 0: resp Http404
|
2019-10-18 00:45:54 +02:00
|
|
|
redirect(replaceUrl(url, cookiePrefs()))
|
|
|
|
|
2019-10-07 16:47:53 +02:00
|
|
|
error Http404:
|
2019-10-21 07:59:22 +02:00
|
|
|
resp Http404, showError("Page not found", cfg)
|
2019-10-07 16:47:53 +02:00
|
|
|
|
2019-09-23 16:12:20 +02:00
|
|
|
extend unsupported, ""
|
2019-09-06 02:42:35 +02:00
|
|
|
extend preferences, ""
|
2019-12-30 11:41:09 +01:00
|
|
|
extend resolver, ""
|
2019-09-15 12:10:43 +02:00
|
|
|
extend rss, ""
|
2019-09-13 22:24:58 +02:00
|
|
|
extend search, ""
|
2019-09-06 02:42:35 +02:00
|
|
|
extend timeline, ""
|
2019-09-21 01:08:30 +02:00
|
|
|
extend list, ""
|
2019-09-20 14:10:10 +02:00
|
|
|
extend status, ""
|
2019-09-06 02:42:35 +02:00
|
|
|
extend media, ""
|
2019-12-06 15:15:56 +01:00
|
|
|
extend embed, ""
|