Search code examples
4d-database

can't change the default homepage with 4D


i'm trying to follow this tutorial to start with 4d server web. http://doc.4d.com/4Dv16/4D/16/Serveur-Web.200-3246839.fe.html

i've disabled the default homepage index.html (and even deleted the actual file in the WebFolder folder) and then added these few lines on the On Web Connection method

C_TEXT($1)
Case of
  :($1="/")
     WEB SEND FILE("new_index.html")
End case

but still i get the 4d default page when i go to localhost:8080/ i then found out the method isn't even called unless i add something to the url (like localhost:8080/something)


Solution

  • If you have index.html listed in the database settings as the default home page then it will load that page (and sometimes it will create it if it does not exist).

    Furthermore, using an html extension will not run any dynamic code, to invoke code you must either use an shtml extension or the file must not exist (OWA/OWC is triggered when the file is not found).

    This tech tip still applies and gives a good rundown of in what situations the On Web Connection (and On Web Authentication) methods run:
    Tech Tip: How to skip over HTTP and redirect to HTTPS: Part 2 (The Web decoy folder)

    Quote:

    The On Web Authentication database method is (by default) only called in the following situations:

    • when 4D receives a URL beginning with 4DACTION/
    • when 4D receives a URL beginning with 4DMETHOD/
    • when 4D receives a URL beginning with 4DCGI/
    • when 4D receives a URL requesting a static page that does not exist
    • when 4D processes a 4DSCRIPT tag in a semi-dynamic page
    • when 4D processes a 4DLOOP tag based on a method in a semi-dynamic page.

    Note: The On Web Authentication database method expects a Boolean value to be returned in $0; True = request accepted, False = request rejected. The default value if $0 is not returned is True which means all requests are accepted.

    The On Web Connection database method is (by default) called in the following cases:
    When connecting a browser to a 4D Web server operating in contextual mode. The database method is called with the /... URL.

    • When 4D receives the /4DMETHOD URL. The Web server switches to contextual mode and the database method is called with the /4DMETHOD/MethodName URL in $1.
      When 4D receives the /4DCGI URL. The database method is called with the /4DCGI/ URL in $1.
    • When a Web page is called with a URL of type / that is not found. The database method is called with the URL as $1.
    • When a Web page is called with a URL of type / and no home page has been defined by default. The database method is called with the URL as $1.

    So (by default) if the web visitor is requesting a page, and that page exists in the webfolder at the location specified in the URL, that page will be automatically sent back to the customer without any special processing. This is fine in most situations but the developer can gain much greater control over the requests by implementing a web decoy folder.

    So, If you want the / url to run your code you could use either of these approaches:

    • use an index.shtml (notice the s in shtml)
    • delete the entry in the database settings (so the default page field in the is empty)

    When modifying the Web Configuration options in 4D, the User Settings will take precedence over the Database Settings.

    if User Settings are enabled, make sure to check both User Settings and Database Settings.

    The user settings are accessible under the following menu options:

    enter image description here

    or

    enter image description here