Skip to content

Commit

Permalink
refactor(handler) drop ternary function for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed Feb 22, 2023
1 parent 5fe93a5 commit fa70e70
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/pegasus/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ local Response = require 'pegasus.response'
local mimetypes = require 'mimetypes'
local lfs = require 'lfs'

local function ternary(condition, t, f)
if condition then return t else return f end
end

local Handler = {}
Handler.__index = Handler

Expand Down Expand Up @@ -112,7 +108,10 @@ function Handler:processRequest(port, client, server)
end

if request:path() and self.location ~= '' then
local path = ternary(request:path() == '/' or request:path() == '', 'index.html', request:path())
local path = request:path()
if path == '/' or path == '' then
path = 'index.html'
end
local filename = '.' .. self.location .. path

if not lfs.attributes(filename) then
Expand Down

0 comments on commit fa70e70

Please sign in to comment.