Lunox Framework

website·Indexed 30 days ago

https://lunox.js.org

A JavaScript framework inspired by Laravel, featuring a service container, facades, an Artisan command-line console, and a query builder. It provides comprehensive tools for routing, middleware, controllers, validation, and error handling for building HTTP-driven applications.

Tokens
20K
Snippets
143
Records
173
Agent score
45%

What's inside Lunox

  1. Overview of Lunox Laravel-Flavoured Node.js Framework

    Lunox is a Node.js framework designed to provide a 'Laravel-flavoured' experience, aiming to support basic Laravel features while maintaining simplicity for Node.js developers.
  2. Overview of the Lunox Framework

    Lunox is a lightweight Node.js MVC framework designed to bring Laravel features into the Node.js environment. It is built on top of Polka (HTTP server) and Vite (frontend tooling). Key architectural features include support for facades, macros, service containers, middleware, and artisan commands, making it a bridge for Laravel developers moving to Node.js.
  3. Overview of Lunox Views

    Views in Lunox separate application logic from presentation logic. They are stored in the resources/views directory. Lunox leverages Vite for automatic conversion of template files to JavaScript and supports Hot Module Replacement (HMR) during development.
  4. Overview of the Lunox Framework

    Lunox is a lightweight Node.js MVC framework designed to bring Laravel's features and syntax to the Node.js environment. It is built on top of polka for the HTTP server and vite for frontend tooling. Key architectural features include support for facades, macros, service containers, middleware, and artisan commands, making it a bridge for Laravel developers transitioning to Node.js.
  5. Manage the HTTP Kernel entry point

    HTTP requests are handled by the Http Kernel (defined in index.ts). The kernel's startup process involves: loading global helper functions from autoload.ts, bootstrapping the application, loading configuration, and registering/booting all service providers.
  6. Understand the Lunox Request Lifecycle and Node.js Event Loop

    Unlike PHP-based frameworks (like Laravel) where the application terminates after each request, Lunox runs on a Node.js event loop and remains active continuously. Developers must ensure that every request either returns a response or throws an exception to prevent the application from hanging. Because the application persists, singletons are shared globally across the entire application; they should only be used for instances intended to be shared across all requests.
  7. Understand the Lunox Request Lifecycle and Response Handling

    Unlike PHP frameworks (like Laravel) where the application terminates after every request, Lunox runs on a Node.js event loop and remains active continuously. Because the application does not automatically terminate, developers must ensure that every request handled by Lunox either returns a response or throws an Exception to prevent the application from hanging.
  8. Flash data and input to session during redirects

    The RedirectResponse instance provides methods to store temporary data in the session that is deleted after the next request:

    1. with(data): Flashes custom data to the session. Access it via req.session().get('key').
    2. withInput(): Flashes the current request's input data to the session (useful for validation errors). Access it via req.session().old('key').
    // Flash custom error message
    return redirect('someurl')->with({
        error: 'Some Error Message'
    });
    // Access via: req.session().get('error')
    
    // Flash current request input
    return back()->withInput();
    // Access via: req.session().old('username')
  9. Pass parameters to middleware

    Middleware handle methods can accept additional parameters after req and next. These parameters are passed in the route definition by appending a colon and a comma-separated list of values to the middleware alias.
    // Middleware definition
    class ExampleMiddleware implements Middleware {
      async handle(req, next, param1, param2) {
        console.log(param1, param2);
        return next(req);
      }
    }
    
    // Route definition
    Route.get("/example", () => "OK").middleware("example:param1,param2");
  10. Run and watch a Lunox app in development

    Use the pnpm dev script to run your Lunox application in development mode. This command creates and watches files in the dist directory and starts the application on localhost:8000 by default. The default port can be modified in the .env file.
    pnpm dev
  11. Perform redirects using global helpers

    Use the global redirect() helper to send a user to a specific URL, or the back() helper to redirect them to the previous URL. Both return an instance of RedirectResponse.
    // Redirect to a specific path
    Route.post("/login", () => {
      return redirect("/dashboard");
    });
    
    // Redirect to the previous URL
    return back();