"Fossies" - the Fresh Open Source Software Archive

Member "geoserver-2.18.1/user/community/scripting/js/app.html" (19 Nov 2020, 11138 Bytes) of package /linux/www/geoserver-2.18.1-htmldoc.zip:


The requested HTML page contains a <FORM> tag that is unusable on "Fossies" in "automatic" (rendered) mode so that page is shown as HTML source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    2   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
    4 <head>
    5   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    6   
    7   <title>The App Hook &mdash; GeoServer 2.18.1 User Manual</title>
    8   <link rel="stylesheet" href="../../../_static/blueprint/screen.css" type="text/css" media="screen, projection" />
    9   <link rel="stylesheet" href="../../../_static/blueprint/print.css" type="text/css" media="print" /> 
   10   <!--[if IE]>
   11   <link rel="stylesheet" href="../../../_static/blueprint/ie.css" type="text/css" media="screen, projection" />
   12   <![endif]-->
   13   <link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
   14   <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
   15   <script type="text/javascript">
   16     var DOCUMENTATION_OPTIONS = {
   17         URL_ROOT:    '../../../',
   18         VERSION:     '2.18.1',
   19         COLLAPSE_MODINDEX: false,
   20         FILE_SUFFIX: '.html'
   21     };
   22   </script>
   23   <script type="text/javascript" src="../../../_static/jquery.js"></script>
   24   <script type="text/javascript" src="../../../_static/doctools.js"></script>
   25   <script type="text/javascript" src="../../../_static/searchtools.js"></script>
   26   <script type="text/javascript" src="../../../searchindex.js"></script>
   27   <link rel="shortcut icon" href="../../../_static/geoserver.ico"/>
   28       <link rel="search" title="Search" href="../../../search.html" />
   29       <link rel="top" title="GeoServer 2.18.1 User Manual" href="../../../index.html" />
   30       <link rel="up" title="JavaScript" href="index.html" />
   31       <link rel="next" title="The WPS Hook" href="wps.html" />
   32       <link rel="prev" title="JavaScript" href="index.html" />
   33 </head>
   34 <body class="community/scripting/js/app">
   35   <div id="header" class="selfclear">
   36     <div class="wrap selfclear">
   37       <div id="logo"><a href="../../../index.html">GeoServer 2.18.1 User Manual</a></div>
   38       <ul id="top-nav">
   39         <li class="first"><a href="http://geoserver.org/about">About</a></li>
   40         <li><a href="http://blog.geoserver.org/">Blog</a></li>
   41         <li><a href="http://geoserver.org/download">Download</a></li>
   42         <!--<li><a href="../../../index.html">Documentation</a></li>-->
   43       </ul>
   44         <form id="quick-search" action="../../../search.html" method="get">
   45           <fieldset>
   46             <input type="hidden" name="check_keywords" value="yes" />
   47             <input type="hidden" name="area" value="default" />
   48             <input id="quick-search-query" type="text" name="q" accessKey="q" name="searchQuery.queryString" size="25" value="Search Documentation&hellip;" size="20" tabindex="3" onblur="if(this.value=='') this.value='Search Documentation&hellip;';" onfocus="if(this.value=='Search Documentation&hellip;') this.value='';" />
   49             <input id="quick-search-submit" type="image" value="Search" src="../../../_static/chrome/search_icon_green.png" />
   50           </fieldset>
   51         </form>
   52     </div><!-- /.wrap -->
   53   </div><!-- /#header -->
   54   <div id="main">
   55     <div class="wrap selfclear">
   56       <div id="content-left" class="content-border"></div>
   57       <div id="content">
   58 <ul id="breadcrumbs">
   59   
   60   <li><a href="../../../index.html">GeoServer 2.18.1 User Manual</a> &raquo;</li>
   61   <li><a href="../../index.html" accesskey="U">Community modules</a> &raquo;</li>
   62   <li><a href="../index.html" accesskey="U">Scripting</a> &raquo;</li>
   63   <li><a href="../reference.html" accesskey="U">Scripting Reference</a> &raquo;</li>
   64   <li><a href="index.html" accesskey="U">JavaScript</a> &raquo;</li>
   65   <li>The App Hook</li>
   66 </ul>
   67 <ul id="relatedlinks" class="selfclear">
   68   <li class="first">
   69     <a href="../../../py-modindex.html" title="Python Module Index"
   70        accesskey="">modules</a></li>
   71   <li>
   72     <a href="wps.html" title="The WPS Hook"
   73        accesskey="N">next</a>|</li>
   74   <li>
   75     <a href="index.html" title="JavaScript"
   76        accesskey="P">previous</a>|</li>
   77 </ul>
   78         
   79   <div class="section" id="the-app-hook">
   80 <h1>The App Hook<a class="headerlink" href="#the-app-hook" title="Permalink to this headline"></a></h1>
   81 <p>In JavaScript the app hook is based on
   82 <a class="reference external" href="http://wiki.commonjs.org/wiki/JSGI">JSGI</a> which provides a common interface
   83 for JavaScript web application development.  The app script must export a
   84 function named <code class="docutils literal notranslate"><span class="pre">app</span></code> that accepts a <code class="docutils literal notranslate"><span class="pre">request</span></code> object and returns a
   85 <code class="docutils literal notranslate"><span class="pre">response</span></code> object.</p>
   86 <div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kr">export</span><span class="p">.</span><span class="nx">app</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">request</span><span class="p">)</span> <span class="p">{</span>
   87   <span class="c1">// handle the request and return a response</span>
   88 <span class="p">}</span>
   89 </pre></div>
   90 </div>
   91 <p>The function must be exported from a file named <code class="docutils literal notranslate"><span class="pre">main.js</span></code> in a named
   92 <em>application directory</em>.  Application directories live under the
   93 <code class="docutils literal notranslate"><span class="pre">scripts/apps</span></code> directory in the root of the data directory:</p>
   94 <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">GEOSERVER_DATA_DIR</span><span class="o">/</span>
   95   <span class="o">...</span>
   96   <span class="n">scripts</span><span class="o">/</span>
   97     <span class="n">apps</span><span class="o">/</span>
   98       <span class="n">app1</span><span class="o">/</span>
   99         <span class="n">main</span><span class="o">.</span><span class="n">js</span>
  100         <span class="o">...</span>
  101       <span class="n">app2</span><span class="o">/</span>
  102         <span class="n">main</span><span class="o">.</span><span class="n">js</span>
  103         <span class="o">...</span>
  104 </pre></div>
  105 </div>
  106 <p>The application is web accessible from the path <code class="docutils literal notranslate"><span class="pre">/script/apps/{app}</span></code> where
  107 <code class="docutils literal notranslate"><span class="pre">{app}</span></code> is the name of the application. All requests that start with this path
  108 are dispatched to the <code class="docutils literal notranslate"><span class="pre">app</span></code> function in <code class="docutils literal notranslate"><span class="pre">main.js</span></code>.</p>
  109 <div class="section" id="hello-world-example">
  110 <h2>Hello World Example<a class="headerlink" href="#hello-world-example" title="Permalink to this headline"></a></h2>
  111 <p>In this example a simple “Hello World” application is built.  The first step is
  112 to create a directory for the app named <code class="docutils literal notranslate"><span class="pre">hello</span></code>:</p>
  113 <div class="highlight-default notranslate"><div class="highlight"><pre><span></span>cd $GEOSERVER_DATA_DIR/scripts/apps
  114 mkdir hello
  115 </pre></div>
  116 </div>
  117 <p>Next step is to create the <code class="docutils literal notranslate"><span class="pre">main.js</span></code> file:</p>
  118 <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">cd</span> <span class="n">hello</span>
  119 <span class="n">touch</span> <span class="n">main</span><span class="o">.</span><span class="n">js</span>
  120 </pre></div>
  121 </div>
  122 <p>Within the app function the following things will happen:</p>
  123 <ol class="arabic simple">
  124 <li><p>Report an HTTP status code of 200</p></li>
  125 <li><p>Declare the content type of the response, in this case “text/plain”</p></li>
  126 <li><p>Generate the body of response, in this case the string “Hello World”</p></li>
  127 </ol>
  128 <p>This is accomplished with the following code:</p>
  129 <div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kr">export</span><span class="p">.</span><span class="nx">app</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">request</span><span class="p">)</span> <span class="p">{</span>
  130   <span class="k">return</span> <span class="p">{</span>
  131     <span class="nx">status</span><span class="o">:</span> <span class="mi">200</span><span class="p">,</span> <span class="c1">// step 1</span>
  132     <span class="nx">headers</span><span class="o">:</span> <span class="p">{</span><span class="s2">&quot;Content-Type&quot;</span><span class="o">:</span> <span class="s2">&quot;text/plain&quot;</span><span class="p">},</span> <span class="c1">// step 2</span>
  133     <span class="nx">body</span><span class="o">:</span> <span class="p">[</span><span class="s2">&quot;Hello World&quot;</span><span class="p">]</span> <span class="c1">// step 3</span>
  134   <span class="p">};</span>
  135 <span class="p">};</span>
  136 </pre></div>
  137 </div>
  138 <p>The body of the response shown above is an array.  In general, this can be any
  139 object with a <code class="docutils literal notranslate"><span class="pre">forEach</span></code> method.  In this way, an app can returned chunked
  140 content instead of returning the entire body content at once.</p>
  141 </div>
  142 </div>
  143 
  144 
  145       <div class="selfclear pagination-nav">
  146           <div class="leftwise"><strong>Previous</strong>: <a href="index.html" title="previous chapter">JavaScript</a></div>
  147           <div class="rightwise"><strong>Next</strong>: <a href="wps.html" title="next chapter">The WPS Hook</a></div>
  148       </div>
  149       </div><!-- /#content> -->
  150       <div id="content-right" class="content-border"></div>
  151   <div id="sidebar" class="contrast">
  152       <div id="toc" class="section">
  153         <h3 class="pngfix">Table Of Contents</h3>
  154         <ul>
  155 <li><a class="reference internal" href="#">The App Hook</a><ul>
  156 <li><a class="reference internal" href="#hello-world-example">Hello World Example</a></li>
  157 </ul>
  158 </li>
  159 </ul>
  160 
  161         <div class="section-footer"></div>
  162       </div>
  163         <div class="section">
  164           <h3>Continue Reading</h3>
  165           <ul>
  166             <li>Previous: <a href="index.html" title="previous chapter">JavaScript</a></li>
  167             <li>Next: <a href="wps.html" title="next chapter">The WPS Hook</a></li>
  168           </ul>
  169         </div>
  170         <div class="section">
  171         <h3>This Page</h3>
  172         <ul class="this-page-menu">
  173                 
  174         <li><a href="https://github.com/geoserver/geoserver/tree/master/doc/en/user/source/community/scripting/js/app.rst">Edit</a></li>
  175         </ul>
  176         </div>
  177   </div><!-- /#sidebar -->
  178   </div><!-- /.wrap> -->
  179 </div><!-- /#main -->
  180 <div id="footer">
  181   <div class="wrap">
  182     &copy; Copyright 2020, Open Source Geospatial Foundation. License <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution</a>.
  183     Last updated on Nov 19, 2020.
  184     Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
  185   </div><!-- /.wrap> -->
  186 </div><!-- /#footer -->
  187   </body>
  188 </html>