import mike, nimja, strutils, json, strformat, httpClient, dotenv, ./lib/[mics, htmx], ./db/users, ./model/[model, rand], ./controller/[signup, login, htmx, admin] load() "/^path" -> before[post, get]: var path2 = ctx.pathParams["path"] echo(fmt"[mike] before request: {ctx.httpMethod} {path2}") "/" -> [get, post]: var user1 = ctx.cookies.getOrDefault("user", "") user = getUserFromCookie(user1) echo user.firstName compileTemplateFile("view" / "index.html", baseDir = getScriptDir()) "/shop" -> get: var user1 = ctx.cookies.getOrDefault("user", "") user = getUserFromCookie(user1) compileTemplateFile("view" / "shop.html", baseDir = getScriptDir()) "/contact" -> get: var user1 = ctx.cookies.getOrDefault("user", "") user = getUserFromCookie(user1) compileTemplateFile("view" / "contact.html", baseDir = getScriptDir()) "/cart" -> get: var user1 = ctx.cookies.getOrDefault("user", "") user = getUserFromCookie(user1) compileTemplateFile("view" / "cart.html", baseDir = getScriptDir()) "/checkout" -> get: var user1 = ctx.cookies.getOrDefault("user", "") user = getUserFromCookie(user1) compileTemplateFile("view" / "checkout.html", baseDir = getScriptDir()) "/shop/:id" -> get: var prodId = capitalizeAscii(ctx.pathParams["id"]) user1 = ctx.cookies.getOrDefault("user", "") user = getUserFromCookie(user1) compileTemplateFile("view" / "shop-detail.html", baseDir = getScriptDir()) "/testimonial" -> get: var user1 = ctx.cookies.getOrDefault("user", "") user = getUserFromCookie(user1) compileTemplateFile("view" / "testimonial.html", baseDir = getScriptDir()) "/signup" -> [get, post]: ctx.signup() "/login" -> get: var user1 = ctx.cookies.getOrDefault("user", "") user = getUserFromCookie(user1) compileTemplateFile("view" / "login.html", baseDir = getScriptDir()) "/logout" -> get: ctx &= initCookie("user", "") ctx.redirect("/") "/htmx/login" -> post: ctx.htmxLogin() "/htmx/email" -> post: htmxEmail(ctx) "/htmx/password" -> post: htmxPassword(ctx) "/htmx/fname" -> post: htmxFirstName(ctx) "/htmx/lname" -> post: htmxLastName(ctx) "/htmx/phone" -> post: htmxPhone(ctx) "/:path" -> get: var user1 = ctx.cookies.getOrDefault("user", "") user = getUserFromCookie(user1) compileTemplateFile("view" / "404.html", baseDir = getScriptDir()) # Experimental "/hi" -> get: var user1 = ctx.cookies.getOrDefault("user", "") user = getUserFromCookie(user1) uploadcare_pub_key = getEnv("UPLOAD_CARE_PUBLIC_KEY") compileTemplateFile("view" / "hi.html", baseDir = getScriptDir()) "/delete-hi" -> post: var client = newHttpClient() uploadcare_pub_key = getEnv("UPLOAD_CARE_PUBLIC_KEY") uploadcare_secret_key = getEnv("UPLOAD_CARE_SECRET_KEY") client.headers = newHttpHeaders({"Authorization": fmt"Uploadcare.Simple {uploadcare_pub_key}:{uploadcare_secret_key}"}) var form = ctx.urlForm echo form var img_uuid = form["img1"] echo img_uuid echo fmt"https://api.uploadcare.com/files/{img_uuid}/storage/" try: let response = client.request(fmt"https://api.uploadcare.com/files/{img_uuid}/storage/", httpMethod = HttpDelete) echo response.status finally: client.close() var js = parseJson("""{"status": "success"}""") ctx.send(js) "/admin" -> get: compileTemplateFile("view" / "admin" / "index.html", baseDir = getScriptDir()) "/admin/add-product" -> [get, post]: ctx.adminAddProduct() "/htmx/admin/product-name" -> post: ctx.htmxProductName() "/htmx/admin/description" -> post: ctx.htmxProductDescription() "/htmx/admin/product-price" -> post: ctx.htmxProductPrice() "/htmx/admin/product-quantity" -> post: ctx.htmxProductQuantity() "/admin/add-image" -> get: var uploadcare_pub_key = getEnv("UPLOAD_CARE_PUBLIC_KEY") compileTemplateFile("view" / "admin" / "addimage.html", baseDir = getScriptDir()) "/jj" -> post: var form = ctx.urlForm echo form var img_uuid = form["img1"] echo img_uuid var js = parseJson(fmt"""{{"status": "success", "img_uuid": "{img_uuid}"}}""") ctx.send(js) servePublic("src/public", "/static") run()