Skip to content

Fix frontend-core.init #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## [Unreleased]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

## [Unreleased]

- Invalidate `index_body` cache in case of re-init.
- Make error messages more clear.
- Enhance options validation.

## [7.7.0]

- Updated Tarantool favicon.
Expand Down
29 changes: 25 additions & 4 deletions frontend-core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,27 +151,46 @@ local function set_variable(name, value)
end

local function init(httpd, options)
if type(httpd) ~= 'table' then
local err = string.format(
"bad argument #1 to frontend-core.init" ..
" (table expected, got %s)", type(httpd)
)
error(err, 2)
end
if options == nil then
options = {}
elseif type(options) ~= 'table' then
local err = string.format("bad argument #2 to init" ..
" (?table expected, got %s)", type(options))
local err = string.format(
"bad argument #2 to frontend-core.init" ..
" (?table expected, got %s)", type(options)
)
error(err, 2)
end

local enforce_root_redirect
if options.enforce_root_redirect == nil then
enforce_root_redirect = true
elseif type(options.enforce_root_redirect) ~= 'boolean' then
local err = string.format("bad argument options.enforce_root_redirect" ..
" to init (?boolean expected, got %s)", type(options.enforce_root_redirect))
local err = string.format(
"bad argument options.enforce_root_redirect" ..
" to frontend-core.init (?boolean expected, got %s)",
type(options.enforce_root_redirect)
)
error(err, 2)
else
enforce_root_redirect = options.enforce_root_redirect
end

if options.prefix == nil then
prefix = ''
elseif type(options.prefix) ~= 'string' then
local err = string.format(
"bad argument options.prefix" ..
" to frontend-core.init (?string expected, got %s)",
type(options.prefix)
)
error(err, 2)
else
prefix = options.prefix
end
Expand Down Expand Up @@ -200,6 +219,8 @@ local function init(httpd, options)
end)
end

index_body = nil

add('core', core_bundle)
return true
end
Expand Down