guzba / mummy

An HTTP and WebSocket server for Nim that returns to the ancient ways of threads.
MIT License
281 stars 11 forks source link

Make routes public #101

Closed ThomasTJdev closed 10 months ago

ThomasTJdev commented 10 months ago

By making the routes: seq[Route] public it's possible to create Router elements in different files and combine them later.

fileA.nim

import
  mummy, mummy/routers

var contractsRouter*: Router
contractsRouter.get("/contracts/api/items", routeContractsApiItems)
contractsRouter.get("/contracts/api/approvals", routeContractsApiApprovals)

fileB.nim

import
  mummy, mummy/routers

var personRouter*: Router
personRouter.get("/person/api/names", routePersonApiNames)
personRouter.get("/person/api/emails", routePersonApiEmails)

fileC.nim

import
  mummy, mummy/routers

import
  ./fileA,
  ./fileB

var mainRouter: Router
mainRouter.get("/", routeMain)
mainRouter.get("/login", routeMainLogin)

for route in contractsRouter.routes:
  mainRouter.route.add(route)

for route in personRouter.routes:
  mainRouter.route.add(route)

let server = newServer(mainRouter)

server.serve(Port(8080))
guzba commented 10 months ago

Tagged in release 0.3.6