Create server

How to install?

npm i --save vqua-server

Example

const app = createServer({ routes: [], layout: (html, data) => '', publicPath: './dist', containerPath: './build/containers', }) app.listen(8080)

Description

Function createServer return instance of simple node http server.

When a request arrives at the server, the path is parsed and the first matched vqua route is located on it. After that, control is passed to the action function specified in the route.

The action method takes two request, response arguments. With one exception, for response object is added two callbacks - send and redirect, which will work both on the server and in the browser. Of course for the browser you need to use package vqua-browser.

To see how everything works right away and together, use ready boilerplate

Arguments for createServer(object)

All arguments are required.

routes - array of routes (vqua-routes)

layout - function callback(html, data)
html - component of the controller, converted to an html string
data - The data returned by the controller is converted into a JSON string

Example layout:

const layout = (html = '', data = '') => { return ( '<html>' + '<head>' + '<meta charset="utf-8">' + '<link rel="stylesheet" type="text/css" href="/index.css">' + '</head>' + '<body>' + '<div id="app">' + html + '</div>' + '<script id="app-cache" type="application/json">' + data + '</script>' + '<script src="/index.js" type="text/javascript"></script>' + '</body>' + '</html>' ) }

publicPath - the path to the folder where static files are stored

containerPath - the path to the folder where the containers are stored (vqua top-level components)

Function action(request, response)

request- in addition to the standard parameters http request contain:

response- in addition to the standard parameters http response contain: