1.0.3 • Published 1 year ago

https-quick v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

https-quick is a drop in for require('https') it has keys and certificates built in and some additional functionality for when you just want to throw together a quick https server https-quick provides a https certificate and ca certificate for

which in this simplest form executes

when the quick function is called https-quick

  • adds onerror and onlistening functions
  • calls server.listen
  • returns the server object for chaining the exposed quick function takes parameters in any order

  • the first number in the parameter list is used as the port i.e quick(2154) will start the server listening on port 2154

  • the first function in the parameter list will be used for the onrequest callback

  • if the string 'hello' is found within the parameter list

    • the server will return a simple hello page on the url /hello
    • it also provides /favicon.ico
    • the cacert can be downloaded from /cacert
    • it adds cors support, for all origins to get and post requests
    • it adds a 'cache-control:no-store' header
  • if the string 'nokeys' is not present

    • adds keyboard event to allow escape to be pressed to quit the process

note :

if the parameter 'hello' is used, https-quick can potentially respond to a request before any user defined request listeners, therefore when using the 'hello' parameter later request listeners need to check that the response writableEnded flag is set to false before processing the request

  • it requires the request and response streams as arguments
  • the response has statusCode 200
  • the response has content-type text/plain
  • the response has body that contains the text in msg

  • it requires the request and response streams as arguments
  • the response has statusCode 400
  • the response has content-type text/plain
  • the response has body that contains the text in msg

  • it requires the request and response streams as arguments
  • the response has statusCode 404
  • the response has content-type text/html
  • the response has body that contains the text from msg

add a url to serve

  • url, the url to serve, if the url already exists it is removed

  • callback, can take a number of forms

    • a function to be called when a request for the url is made, the function is called with arguments req,res
    • a string taken to be html and given in response
    • an object

      • if the object has a 'file' key this is taken as a filename if the object has a 'ins' key this is used to search and replace within the file text

      • if the object has a 'string' key this is taken as html if the object has a 'ins' key this is used to search and replace within the html

a number of functions allow strings to be inserted into text, by supplying an object whose

  • the keys are surrounded by double braces '{' and used as the search parameter, all occurrences are replaced
  • the value is used for the replace text

assigns a file to be served when the given url is accessed, if the insert parameter is given ( see above ), the file is converted to text and search and replace is performed on the text

generates a random alpha-numeric url, 10 characters in length if callback is given quick.url(url,callback) is called

removes the given from the current list

serve the files in directory dir from the url starting with baseurl the exclude parameter is an array of relative paths from dir to exclude from serving

remove the directory dir from being served from baseurl

processes a post request with content-type application/json returns a promise which resolves to a javascript json value

send a html response, html is the string to return and search and replace is performed ( see above ) using the insert parameter

send a json response

send a file if the insert parameter is given the file is converted to text and search and replace performed ( see above )

a convenience function to test if the given file resolves into directory dir

  • returns the absolute filename if true
  • false on failure

a convenience function to test if a given file file exists in directory dir return a promise that resolves into the absolute filename if true or false on failure


example useage:

see github examples directory for more woking examples

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago