No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Arthur Poulet b4a01466a4 minor 3 years ago
DOCUMENTATION minor 3 years ago
app Improve cookie system 4 years ago
bin add verbosity option 4 years ago
certs add certificate 4 years ago
lib Regexp escaping for route loader 4 years ago
nephos change File.exists to File.exist (depreciated) 4 years ago
test update README and fix utf-8 issue on gitlab CI 4 years ago
.gitignore update documentation 4 years ago
.gitlab-ci.yml add internet tests to gitlab ci 4 years ago
CHANGELOG add verbosity option 4 years ago
Gemfile remove puma requirement 4 years ago
Gemfile.lock remove puma requirement 4 years ago
Procfile update Procfile 4 years ago
README.md update README and fix utf-8 issue on gitlab CI 4 years ago
Rakefile improve functional tests 4 years ago
nephos-server.gemspec remove puma requirement 4 years ago
routes.rb Improve cookie system 4 years ago
version add verbosity option 4 years ago

README.md

Nephos Ruby Server

Gem Version

This is a minimal web server, based on rack and puma. It is written in ruby. It also gives you a minimal architecture to speed up your application bootstrap.

Features provided:

  • Controllers: gives you a resource logic.
  • Render: easier render content to the client.
  • Router: create a robust and simple routing system, with url variables.

Features which will not be provided by nserver:

  • Templating (HTML with variables, loops, …): It already exists and it is easy to implement.
  • Database orm and connector: It already exists and simple to implement too.

Start

gem install nephos # download the server and executables
ngenerator application MyApp # generate the application
cd MyApp # go in
nserver -p 8080 -h 0.0.0.0 # start the server. port is not required, neither host

nserver is an executable designed to start the server easly. It can take few arguments, all optionnal:

  • -p: port to listen
  • -h: host to listen (network address)
  • -e: environment (default is development, can be set to production)
  • -d: daemonize the process
  • -k: kill daemonized process

Documentation

Guides

Theses guides will provide you knowlegde about everything you can use in the application.

Examples

Production and environment

To avoid information leaks from your application, set the environment variable export ENVIRONMENT=production, or run the server with -e production parameter. When an error occurs, the backtrace will be print to the client in the rendered page, unless the server runs in production environment.

Controller

Every routes will call a method from a controller. To create a controller, add a ruby file to app/, with a class inherited by Nephos::Controller You should user ngenerator --controller NAME to generate a new controller.

class Example < Nephos::Controller
  def root
    cookies["last_visit"] = Time.now
    if params["index"] == "true"
      return {plain: "index"}
    else
      return :empty
    end
  end
end

Rendering

To render a content to the client, you can return informations from a Controller method:

return 404
return {status: code}
return {status: code, content: "Not today"}
return {json: {status: "resource created"}, status: 201}
return {plain: "text"}
return {html: "<html><body><h1>:D</h1></body></html>"}
return {type: "image/jpeg", content: File.read("images/photo.jpg")}
return :empty

Routing

The routing (rules to execute the action the user wants), you have to write the /routes.rb file. If the user try to access an url not described in the file, it will automaticaly render a 404 not found.

get url: "/", controller: "MainController", method: "root"       # /
post url: "/add", controller: "MainController", method: "add_url" # /add
post url: "/add/:url", controller: "MainController", method: "add_url" # /add with parameter :url
put url: "/rm", controller: "MainController", method: "rm_url"   # /rm
put url: "/rm/:url", controller: "MainController", method: "rm_url"   # /rm with parameter :url
resource "infos" do
  get url: "/", controller: "MainController", method: "root" # generate /infos
  get url: "/about", controller: "MainController", method: "root" # generate /infos/about
  get url: "/notice", to: "MainController#notice" # generate /infos/notice
end

Developers: Roadmap

TODO v0.7

  • feature to change HTTP header from controller
  • Documentation on architecture (UML)
  • Improved documentation (Tutorial, Improved guides)
  • Improved daemon (/tmp/…/.pid) + multi port

v1 requierements

  • Environement, Daemons, Port, Listen Host, Routables, Arguments
  • Clear architecture
  • Generator readables and powerfull
  • At least 80% tests coverage
  • Performances benchmark
  • Guide about
    • Controllers
    • Routing
    • Api Creation
    • Database creation
    • Web HTML with templating
  • Clear documentation on the features using regexp, options, …

Gitlab Continuous Integration: Gitlab Tests

Github version GitHub version

Released version on ruby-gems Gem Version

Code Quality Code Climate

Nephos gem version Nephos Executables