URL Map

server.map() method is used to point url to specific resource

url.map(string <*pattern>, mix <resource>, string <subject=req.uri>, bool <path=false>, bool <Caseless=true>) : bool

Parameters

This method support pattern, resource, subject, path, Caseless parameters

Only Pattern is required.

pattern

The shell wildcard pattern.

resource

Optional. Can Be a Page Name or Callback Function.

subject

The Subject To test for match default is req.uri

path

Slash in string only matches slash in the given pattern.

CaseLess

Default is Case Insensitive Matching.

Return Values

Returns true if there is a match, false otherwise. If page Name is specified then page will be shown. If Callback if provided function call will be returned.

Examples

Example #1 Simple Test

This will Show Test Msg on test page:

if url.map("/test") then server.send("Test success") end

Example #2 Display single Page

display single page for all request:

url.map("*", "index"); ---> display index page for all request

Example #3 Display Page dynamically

If page not exist on server we can show error msg this way:

if not url.map("*", req.script_name or "index") then server.error("Error Page Not Found", 404); end

Example #4 Display msg 

Try to serve static template File If not found then try to show page or error page

url.map("/ok", function () print("Hi "..env.username) end); ---> display Hi when you go to /ok

server.map method is very useful for handling requests correctly and display appropriate content.