Giter Club home page Giter Club logo

cherry's Introduction

๐Ÿ’ Cherry

Build Status Maintainability Test Coverage

Cherry is a lightweight framework to quickly generate a web server

๐Ÿ”Œ Installation

Use the package manager npm to install Cherry.

npm install @lund-org/cherry

๐Ÿ”ง Usage

Checkout the example in the example folder.

For the development : To use the https mode, you need to generate the ssl keys, you can use this command in the config folder :

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj "/C=FR/ST=./L=./O=./OU=./CN=."

Warning : It doesn't work on Windows, you will only get the key.pem with this command. Let's find the way to do it on stackoverflow ๐Ÿ˜‚


Hooks

Example here

You can hook some events and retrieve informations. It is useful to add some code at specific moment of the workflow.

Hook Name Data sent
beforeStartServer { cherry: <Cherry>, server: <CherryHTTPSServer or CherryHTTPServer> }
afterStartServer { cherry: <Cherry>, server: <CherryHTTPSServer or CherryHTTPServer> }
beforeStopServer { cherry: <Cherry>, server: <CherryHTTPSServer or CherryHTTPServer> }
afterStopServer { cherry: <Cherry>, server: <CherryHTTPSServer or CherryHTTPServer> }
beforeStartOrm { cherry: <Cherry>, orm: <The ORM plugin instance> }
afterStartOrm { cherry: <Cherry>, orm: <The ORM plugin instance> }
beforeStopOrm { cherry: <Cherry>, orm: <The ORM plugin instance> }
afterStopOrm { cherry: <Cherry>, orm: <The ORM plugin instance> }
beforeProcess { request: <CherryIncomingMessage>, response: <CherryServerResponse>, middlewares: <Array<Function>> }
afterProcess { request: <CherryIncomingMessage>, response: <CherryServerResponse>, processResult: <The return value of the callback> }

Route types

Example here and here

There is 2 types of route, the public folders to retrieve raw resources and the configured routes.

โš ๏ธ The public routes are always resolved at first

Public routes
Route Name Description Options
PUBLIC_ROUTE_PUBLIC_FOLDER The folder where we will find a resource.

It's an entrypoint, it means that if you request a route /my/route.html, if you have it as a configured route and the same path available in your public folder, it will retrieve the file in the public folder and then quit
path : The absolute path of the folder
priority (optionnal) : The priority of check
Configured routes
Route Name Description Options
ROUTE_CONTEXT A wrapper of routes which allows to avoid to set the same thing for a bunch of routes.

For example, if you have an admin, you will have a middleware to check the authentication and the rights of the user. To not set it to every routes, you can put in on the ROUTE_CONTEXT and it will apply to subsequent routes
type : The type of route, here ROUTE_CONTEXT
collection : The array of subroutes
name (optionnal) : The name of the route which will be added before the name of the subroutes
method (optionnal) : The default HTTP method of the subroute, can be overriding
path (optionnal) : The leading path which will be added before the path of the subroutes
middlewares (optionnal) : The middlewares to execute for each subroutes
rules (optionnal) : The rules for route parameters if there is some in the path
ROUTE A configured route which will execute your code when requested type : The type of route, here ROUTE
path : The path of the route
callback : The method to execute when the route is requested
name (optionnal) : The name of the route. It can be useful to detect it in a hook
method (optionnal) : The HTTP method of the route, it overrides the value set in the context (if present)
middlewares (optionnal) : The middlewares to execute before accessing to the callback
rules (optionnal) : The rules for route parameters if there is some in the path

๐Ÿ“œ To do list

๐Ÿ“‚ Resources

View engine plugin

ORM plugin

๐Ÿ’ป Applications using Cherry (as a real example)

  • Livedeck-server : This project is the core of the livedeck project. It's the central point between the web/smartphone client and the software client. Like a bridge but with a database.

โœ๏ธ Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

๐Ÿ“– License

MIT

cherry's People

Contributors

dependabot[bot] avatar jumastro avatar mystilund avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

cherry's Issues

Hooks

Add hooks for different components and different states

Plugin management

Already started with the templating management, but enlarge with the hook management

Manage GET parameters

We don't have in the params attributes of the request the GET parameters.

This issue will bring a little upgrade to the request parsing and enable the capacity to have a request plugin (named RequestPlugin).

Enhance route format

Enhance the route system to allow default action attached to a set of routes.
Example : A middleware called for every routes (for checking the duration of each route for example)

Enhance the route declaration to allow the definition of "part of route".
It will avoid to copy/paste the beginning of a path and help to see the different categories
Linked with the feature above, it will allow this :

  • Path begining with "/admin" => Always call a middleware "AuthAdmin"
  • Declaration of a route "/users" which renders the route "/admin/users"
  • Declaration of a route "/categories" which renders the route "/admin/categories"

Manage the assets

Should manage the ressources requested by looking in a public folder (in no route match). Top 1 priority

Debug mode (logger)

Why not adding a toolbar for the html response like symfony where you get additionnal informations in your view ๐Ÿค”

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.