{"size": 3212, "ext": "scrbl", "max_stars_repo_path": "web-server-doc/web-server/scribblings/running.scrbl", "max_stars_repo_name": "jessealama/web-server", "max_stars_repo_stars_event_min_datetime": "2015-01-21T08:11:58.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T08:28:39.000Z", "max_issues_repo_path": "web-server-doc/web-server/scribblings/running.scrbl", "max_issues_repo_name": "jessealama/web-server", "max_issues_repo_issues_event_min_datetime": "2015-01-14T08:06:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-12T14:38:40.000Z", "max_forks_repo_path": "web-server-doc/web-server/scribblings/running.scrbl", "max_forks_repo_name": "jessealama/web-server", "max_forks_repo_forks_event_min_datetime": "2015-03-05T15:07:36.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-30T18:59:25.000Z"}
{"max_stars_count": 82, "max_issues_count": 105, "max_forks_count": 37, "avg_line_length": 39.6543209877, "max_line_length": 113, "alphanum_fraction": 0.6771481943}
#lang scribble/doc
@(require "web-server.rkt")

@title[#:tag "run"]{Running Web Servlets}

There are a number of ways to run Web servlets.

@; ------------------------------------------------------------
@section[#:tag "insta"]{Instant Servlets}
@(require (for-label (only-in web-server/insta/insta
                              no-web-browser static-files-path)
                     web-server/http
                     web-server/servlet-env))

@defmodulelang[web-server/insta #:use-sources (web-server/insta/insta)]

The fastest way to get a servlet running in the Web server is to use the 
"Insta" language in DrRacket. Enter the following into DrRacket:

@racketmod[
web-server/insta

(define (start req)
  (response/xexpr
   `(html (head (title "Hello world!"))
          (body (p "Hey out there!")))))
]

And press @onscreen["Run"]. A Web browser will open up showing your new servlet.
This servlet will only be accessible from your local machine.

Behind the scenes, DrRacket has used @racket[serve/servlet] to start a new server
that uses your @racket[start] function as the servlet. 
You are given the entire @racketmodname[web-server/servlet] API.

The following API is provided to customize the server instance:

@defproc[(no-web-browser) void]{
 Calling this will instruct DrRacket to @emph{not} start a Web browser when you press
  @onscreen["Run"].
}

@defproc[(static-files-path [path path-string?]) void]{
 This instructs the Web server to serve static files, such as stylesheets and images, from @racket[path].
}

If you want more control over specific parameters, keep reading about @racketmodname[web-server/servlet-env].

@; ------------------------------------------------------------
@include-section["servlet-env.scrbl"]

@; ------------------------------------------------------------
@section[#:tag "command-line-tools"]{Command-line Tools}
@(require (for-label web-server/configuration/configuration-table
                     web-server/web-server
                     web-server/web-config-sig
                     web-server/web-config-unit
                     web-server/web-server-unit))

@section-index{plt-web-server}

One command-line utility is provided with the @|web-server|:

@commandline{plt-web-server [-f <file-name> -p <port> -a <ip-address> --ssl]}

The optional @tt{file-name} argument specifies the path to a
@racket[configuration-table] S-expression (see @racket[configuration-table->sexpr] for the syntax documentation.)
If this is not provided, the
default configuration shipped with the server is used. The optional
@tt{port} and @tt{ip-address} arguments override the corresponding portions of
the @racket[configuration-table]. If the @tt{ssl} option is provided, then
the server uses HTTPS with @filepath{server-cert.pem} and @filepath{private-key.pem}
in the current directory, with 443 as the default port. (See the @racketmodname[openssl] 
module for details on the SSL implementation.)

The @racket[configuration-table] is given to
@racket[configuration-table->web-config@] and used to construct a
@racket[web-config^] unit, and is linked with the
@racket[web-server@] unit. The resulting unit is invoked, and the
server runs until the process is killed.
