Link to GitHub. Used extern libs:
You can:
- clone the repository:
git clone https://github.com/a1div0/https.git
- install the
https
module usingtarantoolctl
:
tarantoolctl rocks install https://raw.githubusercontent.com/a1div0/https/main/https-1.0.3-1.rockspec
local https = require('https.server')
- acquire a library handlelocal server = https.new(options)
- create new server-objectserver:route(options, proc)
- binds address and handlerserver:start()
- starts the serverserver:stop()
- stop the serverserver:schedule()
- procedure to run on schedule - reissue the certificate when its expiration date comes up
new(options)
This procedure create a new server object with the specified parameters.
The options
parameter, which is a table with fields:
host
- the host to bind toport80
- the port 80 to bind toport443
- the port 443 to bind todns_name
- site name for certificatecert_path
- path to the folder for storing the certificate and for creating temporary files in the process of obtaining a certificatecert_name
- file name of the prepared certificate, or, how to name the certificate when receiving it
For more options see acme-client.
It is possible to automatically route requests between different handlers, depending on the request path. For more information see http-server.
Starts and stop the server.
Checks if the deadline has passed, and if so, starts the process of obtaining a new certificate and restarts the server with a new certificate.
local https = require('https.server')
local function echo_proc(request)
local response = request:render{ text = request.body }
response.headers['x-test-header'] = request.method..' '..request.path;
response.status = 200
return response
end
local options = {
host = '0.0.0.0',
port80 = 80,
port443 = 443,
dns_name = 'mysite.me',
cert_path = 'cert/',
cert_name = 'ssl.pem',
}
local server = https.new(options)
server:route({ path = '/echo' }, echo_proc)
server:start()