Explorar el Código

Isolate Routes

master
Daniel Covington hace 2 días
padre
commit
e1b711a7be
Se han modificado 3 ficheros con 22 adiciones y 17 borrados
  1. +14
    -12
      CLAUDE.md
  2. +3
    -5
      Core/Bootstrap.asp
  3. +5
    -0
      Core/Routes.asp

+ 14
- 12
CLAUDE.md Ver fichero

@@ -101,14 +101,15 @@ reaches `IncludeAll.asp` with one. Add a new `Core/*.asp` class's `#include` lin
web root" reason as everything else in `Core/` — not everything there is a reusable service. Alongside
`IncludeAll.asp` (loads class definitions), `Core/Bootstrap.asp` is the actual construction/wiring step
that used to live directly in `Default.asp`: it sets `Response.Buffer`/`ContentType`, `Dim`s every
page-level variable, `New`s up `App`/`ClockService`/`HttpRequest`/`Router`/`Dispatcher`, registers
routes and the `clockService`, binds the request, and calls `Boot`. Both are included right after each
other from `Default.asp` (`IncludeAll.asp` first, since `Bootstrap.asp`'s `New App` etc. need the class
definitions already loaded). **`Bootstrap.asp` turns `On Error Resume Next` on and deliberately leaves
it on** — `Default.asp`'s `Match`/`Dispatch` calls run under that same error-handling mode before
`Default.asp` itself checks `Err.Number` and calls `On Error Goto 0`. This works because `#include`
(and this nested pair of them) all splice into one compiled script, same as everywhere else in this
file — but it means you can't understand `Default.asp`'s error handling by reading `Default.asp` alone.
page-level variable, `New`s up `App`/`ClockService`/`HttpRequest`/`Router`/`Dispatcher`, includes
`Core/Routes.asp` to register all routes, then registers the `clockService`, binds the request, and
calls `Boot`. Both are included right after each other from `Default.asp` (`IncludeAll.asp` first,
since `Bootstrap.asp`'s `New App` etc. need the class definitions already loaded). **`Bootstrap.asp`
turns `On Error Resume Next` on and deliberately leaves it on** — `Default.asp`'s `Match`/`Dispatch`
calls run under that same error-handling mode before `Default.asp` itself checks `Err.Number` and calls
`On Error Goto 0`. This works because `#include` (and this nested pair of them) all splice into one
compiled script, same as everywhere else in this file — but it means you can't understand `Default.asp`'s
error handling by reading `Default.asp` alone.

**Front controller.** `Public/web.config` rewrites every request that isn't a real file or directory
to `Public/Default.asp` (preserving the query string). `Default.asp` is therefore the single entry
@@ -118,8 +119,9 @@ both live in the two `Core/` includes above:
```
Default.asp
<!--#include IncludeAll.asp --> ' loads every Core/*.asp class definition
<!--#include Bootstrap.asp --> ' New's + wires everything, AddRoute's, Binds, Boots,
' and leaves On Error Resume Next switched on
<!--#include Bootstrap.asp --> ' New's + wires everything, Binds, Boots,
<!--#include Routes.asp --> ' registers all AddRoute's (included by Bootstrap.asp)
' leaves On Error Resume Next switched on
→ oRouter.Match(oApplication.Route) ' -> Dictionary{ControllerName, Params} or Nothing
→ oDispatcher.Dispatch app, routeMatch, controllerKey, oController ' ByRef outputs - see Dispatcher below
→ check Err.Number, then On Error Goto 0 ' closes out the Resume Next opened in Bootstrap.asp
@@ -140,7 +142,7 @@ for where matching a key turns into an actual running controller.
`id`), and two patterns that only differ in segment count can safely map to the same controller — they
never both match the same request, since `Match` requires an exact segment-count match before it even
looks at individual segments (`/greet/{name}` and `/greet/{name}/{id}` for `Greet` is the live example:
`Bootstrap.asp` registers both, and `GreetController.HasId` is only `True` when the longer one
`Routes.asp` registers both, and `GreetController.HasId` is only `True` when the longer one
matched). **What `Router`/patterns do *not* give you**: a generic ASP.NET-MVC-style
`{controller}/{action}/{id}` catch-all that dispatches to *any* controller/action pair. VBScript can't
instantiate a script-defined `Class` from a string, so even a wildcard pattern still needs `Dispatcher`
@@ -160,7 +162,7 @@ needs a static `Select Case controllerKey → New <X>Controller` internally —
unavoidable regardless of which file holds it, but it's confined to `Dispatcher` alone now (this
limitation does NOT apply to picking the *view*, which is dynamic — see `DynamicIncludes` below).
Adding a route means: new controller in `Core/Controllers/`, new view in `Core/Views/` named to match
the controller key, one `AddRoute` call in `Default.asp`, one `Case` branch in `Dispatcher.Dispatch`.
the controller key, one `AddRoute` call in `Core/Routes.asp`, one `Case` branch in `Dispatcher.Dispatch`.

**`App.Route` depends on `HTTP_X_ORIGINAL_URL`, not `PATH_INFO`.** Because `Public/web.config`
internally rewrites every request to `Default.asp`, `PATH_INFO` inside the page is always empty —


+ 3
- 5
Core/Bootstrap.asp Ver fichero

@@ -26,11 +26,9 @@ Set oClockService = New ClockService
Set oRequest = New HttpRequest
Set oRouter = New Router
Set oDispatcher = New Dispatcher

oRouter.AddRoute "/", "Home"
oRouter.AddRoute "/greet/{name}", "Greet"
oRouter.AddRoute "/greet/{name}/{id}", "Greet"

%>
<!--#include file="Routes.asp" -->
<%
' Left switched on deliberately - Default.asp's Match/Dispatch call runs
' under this same On Error Resume Next before checking Err.Number itself.
On Error Resume Next


+ 5
- 0
Core/Routes.asp Ver fichero

@@ -0,0 +1,5 @@
<%
oRouter.AddRoute "/", "Home"
oRouter.AddRoute "/greet/{name}", "Greet"
oRouter.AddRoute "/greet/{name}/{id}", "Greet"
%>

Cargando…
Cancelar
Guardar

Powered by TurnKey Linux.