0.2.1 • Published 3 years ago

ltwt v0.2.1

Weekly downloads
1
License
MIT
Repository
-
Last release
3 years ago

LTWT

npm downloads Maintainability Test Coverage


This is a simple web framework. Right now there are only a few features.

  • Rendering - Templates - Static HTML - Arbitrary Content (photos, video, documents, etc.)
  • Basic Routing

Documentation

LTWT.start()

Will start a HTTP server on port 80 by default. Environmental variable LTWTport can override the default port. This function will block execution of other code

LTWT.registerHandler(route, handler)

Will associate a handler to a specified route. If a request matches the route provided, the request will be forwarded to the handler. The handler must be a function with two arguments or it may be a name referencing a file found in ./routes, the default handler path. The handler file must export a single function with two arguments. Handlers use the variables req and res as reqest and respons objects passed from the http module. Environmental variable LTWThandlerpath can be used to change the handler path.

LTWT.registerAllStatic()

Will register an appropriate handler for all files in the resources/static directory. Only HTML documents are supported at this time. However, support for images is being developed.

LTWT.render.content(filepath, contentType, res)

Will respond with content at specified filepath. The filepath will be rooted in ./resources/static/, the default static content path. The provided contentType will be used in the response to the client. The variable res should be passed from the second argument in a handler function. Environmental variable LTWTstaticpath can be used to change the static content path.

LTWT.render.page(filepath, res)

Will respond with html document at specified filepath. The filepath will be rooted in ./resources/static/, the default static content path. The variable res should be passed from the second argument in a handler function. Environmental variable LTWTstaticpath can be used to change the static content path.

LTWT.render.template(filepath, res, placeholders={}, httpcode=200)

Will respond with template at specified filepath. The filepath will be rooted in ./resources/templates/, the default template content path. The variable res should be passed from the second argument in a handler function. The variable httpcode should be a http response code and is 200 by default. The variable placeholders should be an object with the key as the name of the placeholder in the template and the value as the data to replace the placeholder.

LTWT.render.error(code, href, res, msg='')

Will respond with the specified code which should be an http response code. The href should be the requested resource. This will be logged in the console. The variable res should be passed from the second argument in a handler function. The variable msg is the error message that will be logged in the console.

0.2.1

3 years ago

0.2.0

3 years ago

0.1.0

4 years ago