Skip to content

Commit

Permalink
fix(example): fix the examples to use new plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed Feb 29, 2024
1 parent af9f41d commit b13f5af
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ server:start(function (request, response)
end)
```

Or try the [included examples](example/README.md).

## Features

- Compatible with Linux, Mac and Windows systems
Expand Down
16 changes: 11 additions & 5 deletions example/app.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ package.path = './src/?.lua;./src/?/init.lua;' .. package.path
local Pegasus = require 'pegasus'
local Compress = require 'pegasus.plugins.compress'
local Downloads = require 'pegasus.plugins.downloads'
local Files = require 'pegasus.plugins.files'
-- local TLS = require 'pegasus.plugins.tls'

local server = Pegasus:new({
port = '9090',
location = '/example/root/',
plugins = {
-- TLS:new { -- the tls specific configuration
-- wrap = {
Expand All @@ -30,10 +30,15 @@ local server = Pegasus:new({
-- },

Downloads:new {
prefix = "downloads",
location = '/example/root/',
prefix = 'downloads',
stripPrefix = true,
},

Files:new {
location = '/example/root/',
},

Compress:new(),
}
})
Expand All @@ -47,9 +52,10 @@ server:start(function(req, resp)
end

local data = req:post()

if data then
print(data['name'])
print(data['age'])
print("Name: ", data.name)
print("Age: ", data.age)
end
stop = not not resp:writeFile("./example/root" .. path)
return stop
end)
2 changes: 1 addition & 1 deletion example/copas.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ local Downloads = require 'pegasus.plugins.downloads'
-- @tparam[opt] table opts.sslparams the tls based parameters, see the Copas documentation.
-- If not provided, then the connection will be accepted as a plain one.
-- @tparam[opt] table opts.plugins the plugins to use
-- @tparam[opt] function opts.handler the callback function to handle requests
-- @tparam[opt] function opts.callback the callback function to handle requests
-- @tparam[opt] string opts.location the file-path from where to server files
-- @return the server-socket on success, or nil+err on failure
local function newPegasusServer(opts)
Expand Down
1 change: 1 addition & 0 deletions rockspecs/pegasus-dev-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ build = {
['pegasus.compress'] = 'src/pegasus/compress.lua',
['pegasus.plugins.compress'] = 'src/pegasus/plugins/compress.lua',
['pegasus.plugins.downloads'] = 'src/pegasus/plugins/downloads.lua',
['pegasus.plugins.files'] = 'src/pegasus/plugins/files.lua',
['pegasus.plugins.tls'] = 'src/pegasus/plugins/tls.lua',
}
}

0 comments on commit b13f5af

Please sign in to comment.