-
Notifications
You must be signed in to change notification settings - Fork 36
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
refactor(files) move serving files into a plugin #130
Conversation
3a3d433
to
7c6391c
Compare
853998e
to
b758301
Compare
server:start(function(req) | ||
local data = req:post() | ||
server:start(function(req, resp) | ||
local stop = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need this variable, you can simply return the values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I originally had. I introduced the stop
variable for readability. It makes it clear what the returned result is supposed to be. If results are directly returned one has to mentally parse every return statement, whereas this reads easy as the intent is clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let me know if you want me to change this anyway. No problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree that it's making it more readable, but I'm fine to keep it there as it's just a code example :)
|
||
local path = req:path() | ||
if req:method() ~= "POST" or path ~= "/index.html" then | ||
return stop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return stop | |
return false |
end | ||
stop = not not resp:writeFile("./example/root" .. path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stop = not not resp:writeFile("./example/root" .. path) | |
return not not resp:writeFile("./example/root" .. path) |
end | ||
stop = not not resp:writeFile("./example/root" .. path) | ||
return stop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return stop |
I think we should add more unit tests here. We have entire new modules without any tests. |
ee4642c
to
1ac5fdb
Compare
Finally had some time to write the tests for the 2 new files; test for the json lib, and the files-plugin. |
4f29a4a
to
b13f5af
Compare
this reduces the 'handler' to primary task of running plugins
@EvandroLG I rebased the PR, afetr some of the commits were merged via other PR's. What's left is hard to simplify due to conflicts that would arise. Please have another look. |
@EvandroLG anything I can do to get this moving? |
Super nice stuff, @Tieske! Thanks! :) |
Added the requested docs. Accidentally also pushed the router plugin, but removed that commit again. The files plugin was already in the rockspec. So all changed as requested. |
handler.plugins = plugins or {} | ||
|
||
if location then | ||
handler.plugins[#handler.plugins+1] = Files:new { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure if I agree that a plugin should be called into the handler logic. In my view, the handler logic should work just with stuff that is part of the Pegasus core. I'm curious to see how you envision it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Tieske ?
src/pegasus/json.lua
Outdated
@@ -0,0 +1,62 @@ | |||
-- Wrapper library that supports multiple JSON libraries |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's more like a plugin, right? Why do you think it should be served as part of the Pegasus root?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Tieske ?
src/pegasus/plugins/tls.lua
Outdated
return false | ||
end | ||
print"running TLS" | ||
--print"running TLS" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--print"running TLS" |
server:start(function(req) | ||
local data = req:post() | ||
server:start(function(req, resp) | ||
local stop = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree that it's making it more readable, but I'm fine to keep it there as it's just a code example :)
Looks great, @Tieske! Thanks! |
This builds on top of #127
this reduces the 'handler' to primary task of running plugins