• Stars
    star
    388
  • Rank 106,645 (Top 3 %)
  • Language
    Lua
  • License
    MIT License
  • Created over 9 years ago
  • Updated 6 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿš€ Pegasus.lua is an http server to work with web applications written in Lua language.

pegasus.lua

An http server to work with web applications written in Lua language check the site.

Unix build Lint HuBoard badge Gitter

Installation

To install Pegasus.lua, run:

$ luarocks install pegasus

How does it work?

Follow an example:

local pegasus = require 'pegasus'

local server = pegasus:new({
  port='9090',
  location='example/root'
})

server:start(function (request, response)
  print "It's running..."
end)

Or try the included examples.

Features

  • Compatible with Linux, Mac and Windows systems
  • Easy API
  • Support Lua >= 5.1
  • Native support for HTTP Streaming, aka chunked responses. Check how it works.
  • Native plugin to compress responses using the "gzip" method

API

Parameters

  • host:string Host address where the application will run. By default it uses localhost
  • port:string The port where the application will run. By default it's 9090
  • location:string Path used by Pegasus to search for the files. By default it's the root
  • plugins:table List with plugins
  • timeout:number It's a timeout for estabilishing a connection with the server

Request

Properties

  • path:string A string with the request path
  • headers:table A table with all the headers data
  • method:function The output is the request method as a string ('GET', 'POST', etc)
  • querystring:string It returns a dictionary with all the GET parameters
  • ip:string It returns the client's ip
  • port:number It returns the port where Pegasus is running

Response

Methods

  • addHeader(string:key, string:value) Adds a new header
  • addHeaders(table:headers) It adds news headers
  • statusCode(number:statusCode, string:statusMessage) It adds a Status Code
  • contentType(string:value) Adds a value to Content-Type field
  • write(string:body) It creates the body with the value passed as parameter
  • writeDefaultErrorMessage(statusCode: string, message:body) It sets an HTTP status code and writes an error message to the response
  • writeFile(string:file) It creates the body with the content of the file passed as parameter
  • post():table It returns a dictionary with all the POST parameters
  • redirect(location:string, temporary:boolean): Makes an HTTP redirect to a new location. The status code is set to 302 if temporary is true and false otherwise.
local pegasus = require 'pegasus'

local server = pegasus:new({ port='9090' })

server:start(function (req, rep)
  rep:addHeader('Date', 'Mon, 15 Jun 2015 14:24:53 GMT'):write('hello pegasus world!')
end)

Native Plugin

  • pegasus.plugins.compress
local Pegasus = require 'pegasus'
local Compress = require 'pegasus.plugins.compress'

local server = Pegasus:new({
  plugins = { Compress:new() }
})

server:start()
  • pegasus.plugins.downloads
local Pegasus = require 'pegasus'
local Downloads = require 'pegasus.plugins.downloads'

local server = Pegasus:new({
  plugins = {
    Downloads:new {
      prefix = "downloads",
      stripPrefix = true,
    },
  }
})

server:start()
  • pegasus.plugins.files
local Pegasus = require 'pegasus'
local Files = require 'pegasus.plugins.files'

local server = Pegasus:new({
  plugins = {
    Files:new {
      location = "./",
      default = "index.html",
    },
  }
})

server:start()
  • pegasus.plugins.tls
local Pegasus = require 'pegasus'
local Tls = require 'pegasus.plugins.tls'

local server = Pegasus:new({
  plugins = {
    TLS:new {
      wrap = {
        mode = "server",
        protocol = "any",
        key = "./serverAkey.pem",
        certificate = "./serverA.pem",
        cafile = "./rootA.pem",
        verify = {"none"},
        options = {"all", "no_sslv2", "no_sslv3", "no_tlsv1"},
      },
      sni = nil,
    },,
  }
})

server:start()

Contributing

Install Dependencies

$ make install_dependencies

Running tests

$ make unit_test

More Repositories

1

pageAccelerator

A very light solution to load web pages faster
JavaScript
1,206
star
2

ts-audio

๐ŸŽผ ts-audio is an agnostic library that makes it easy to work with AudioContext and create audio playlists in the browser
TypeScript
310
star
3

transitionEnd

๐Ÿ’ซ TransitionEnd is an agnostic and cross-browser library to work with transitionend event.
HTML
95
star
4

selecting

๐ŸŽฃ A library that allows you to access the text selected by the user
JavaScript
92
star
5

array.lua

A small library with useful methods to handle Lua's table when it's working like an Array
Lua
60
star
6

computer_science_in_lua

๐ŸŒ› Implementation of some classic data structures and algorithms in Lua
Lua
48
star
7

serialized-redis

๐Ÿ”‘ A solution to have lists and dictionaries serialized using redis-py
Python
47
star
8

Feed

Library that makes easy to parse a RSS feed in your client-side.
JavaScript
35
star
9

str

str is a string module with useful methods that don't exist in Lua's core
Lua
29
star
10

simple_test

๐Ÿ‘Œ A powerful, minimalist and easy-to-use Lua unit testing framework.
Lua
22
star
11

P

It's a cross-browser, agnostic and very lightweight library to help you to work with Promise in JavaScript.
JavaScript
22
star
12

lua-watcher

๐Ÿ‘€ A Lua module to monitor files from a specific directory
Lua
20
star
13

video-streaming.lua

๐ŸŽฅ Library that implements MontionJPG technique using Lua and Pegasus.lua
Lua
11
star
14

pipe.lua

An implementation of the `pipeline` operator in Lua
Lua
10
star
15

set-lua

`set-lua` is a complete implementation of the Set data structure in Lua
Lua
10
star
16

Dadado

A cache that automatically removes the least-recently-used items
TypeScript
9
star
17

ReactFormHelper

๐Ÿ”จ Simple way to build forms in React
TypeScript
9
star
18

Hash.lua

Library with useful methods to handle Lua's table when it's working as a Hash.
Lua
9
star
19

ts-indicator

A tiny reading position indicator library
TypeScript
9
star
20

node-compressor

A complete solution to compress static files with node
JavaScript
6
star
21

immutable

`immutable` is a tiny library that makes easy to work with immutable data
Lua
4
star
22

Map

Map works like a hashtable but preserving the key insertion order
Lua
4
star
23

is

Simple way to check whether the current element matched against a selector
JavaScript
4
star
24

setup-lib-js

shell script to create files and directories common to any lib I write in js
Shell
4
star
25

SpaceX-Missions

A web application to follow the latest SpaceX missions
TypeScript
3
star
26

slugify.js

A client-side and server-side solution to convert a text to slug
JavaScript
3
star
27

QueryDOM

Simple Chrome extension to search for elements in the DOM.
JavaScript
3
star
28

memo.lua

An implementation of the `memoize` technique in Lua
Lua
3
star
29

luaDoc

In development
JavaScript
2
star
30

find-by-words

A solution for finding words started by a string. It works well on both front-end and back-end.
JavaScript
2
star
31

jquery-jslide

JavaScript
2
star
32

phonegap-game-of-memory

game of memory built using the api phonegap
JavaScript
2
star
33

copy_to_clipboard

A command-line program to copy the contents of any file to the clipboard
Ruby
2
star
34

maxlength-textarea

complete solution simulation maxlength for textarea element
2
star
35

ts-flatten

A utility function that takes in a value and returns a flatted version of that value
TypeScript
2
star
36

tic-tac-toe

A simple game tic tac toe developed in python
Python
1
star
37

front-end-boilerplate

JavaScript
1
star
38

c-programming

A repository only for c studies
C
1
star
39

metaprogramming_python

Just playing with metaprogramming in Python
Python
1
star
40

mousewheel

JavaScript
1
star
41

grpc-server

This is a simple implementation of a gRPC server in Go, created for study purposes.
Go
1
star
42

parser_html

In development
Lua
1
star
43

ts-object-formatter

A small library designed to format object fields in either snake case or camel case
TypeScript
1
star
44

Observable.js

in development
JavaScript
1
star
45

algorithms-playground

My solutions to leetcode and hackerrank problems
JavaScript
1
star
46

gallery

TypeScript
1
star
47

data_structures_in_js

A collection of data structure developed in JavaScript.
JavaScript
1
star
48

Graph-Coloring

Implementation of problem using Graph Color. Developed in 2008.
Java
1
star
49

ts-weighted-random

Picks a random value from a list based on the weights
TypeScript
1
star
50

myTetris

๐ŸŽฎ Tetris game written in vanilla JavaScript (in development)
JavaScript
1
star
51

dom-playground

Solutions for DOM problems
HTML
1
star
52

async-playground

Solutions for async problems using Thunks, Promises, Generators, etc.
JavaScript
1
star
53

College-Library

Control System library. Using techniques developer, such as MVC and DAO. Developed in 2008.
PHP
1
star
54

ts-css-selector

A CSS selector generator
TypeScript
1
star
55

dotfiles

๐Ÿ’พ My dotfiles
Vim Script
1
star
56

fp_playground

A repository just for Functional Programming studies
JavaScript
1
star
57

HashTable

An experimental implementation of HashTable in Lua just for fun
Lua
1
star
58

whac-a-mole

Implementation of the classic `Whac-A-Mole` game in React
TypeScript
1
star
59

web_worker_playground

Just a simple project to play with Web Worker
JavaScript
1
star