Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

VirtualHost Object

HARADA Koichi edited this page Apr 26, 2020 · 5 revisions

VirtualHost

Constructor

VirtualHost new VirtualHost (host)

Name Type Description
host text Host name
return object VirtualHost object

This method creates and returns a VirtualHost object.

It can be used to diverge routes by named host.

This function just creates a VirtualHost object on memory. So you must register it to the main application using HttpServer.use(VirtualHost) function after you've finished to add routes to the VirtualHost.

When the same path is registered to a VirtualHost and the HttpServer, the route belongs to the VirtualHost has priority.

Example

C_OBJECT($app_o;$vhost_o)
$app_o:=new HttpServer
$app_o.get("/hoge";Formula(DefaultMethodName))

$vhost_o:=new VirtualHost("api.foo.com")
$vhost_o.get("/hoge";Formula(ApiMethodName))

$app_o.use($vhost_o)

In the above case, when the host name and the pass combination is:

  • api.foo.com/hoge : ApiMethodName will be invoked
  • any other host name and the pass "/hoge" : DefaultMethodName will be invoked

Nevertheless of the order of the route registration, routes that matches the virtual host name will be selected, if any.

Properties

Methods

Route configuration

The VirtualHost object has the same routing functions with HttpServer object.

For detail description on each function, please refer to HttpServer page.

Functions provided with this object are:

VirtualHost.all()
VirtualHost.delete()
VirtualHost.get()
VirtualHost.method()
VirtualHost.post()
VirtualHost.put()
VirtualHost.route()
VirtualHost.use()


Clone this wiki locally