sand-http is an HTTP application server module designed for the Sand.js framework. It provides a structured approach to building web applications with features like automatic server lifecycle management, regular expression-based routing, Express.js-style middleware, MVC patterns for controllers and views, and graceful error handling per request. As of version 2.10.2, released in early 2021, the package appears to be in an abandoned or minimal maintenance state, with no significant updates in recent years. It heavily leverages CommonJS module syntax and relies on static Generator Functions for controller actions, a pattern that has largely been superseded by async/await in modern Node.js development. Its unique selling points, such as the `sand.ctx` execution context for helper classes, aim to simplify request-scoped data access within the Sand.js ecosystem. The project emphasizes compatibility with ES6 syntactic features within application code, though the module itself is CommonJS.
npm install sand-httpVerified import paths — ran on the pinned version, not inferred.
This quickstart initializes a Sand.js application with the `sand-http` grain, setting up a basic HTTP server, routes, and a controller. It demonstrates the framework's file structure and the use of static Generator Functions for actions. Access at `http://localhost:3000/`.
Adhere strictly to `static *actionName()` generator function syntax for controller actions. Avoid `async/await` directly in actions unless explicit middleware or context binding is implemented to support it, which is not natively provided by `sand-http` in its current form.
For new projects, consider modern frameworks built with ESM. If using `sand-http`, ensure your project uses CommonJS or a bundler configured to handle CJS modules within an ESM project. Direct `import` statements for `sand-http` will fail at runtime.
Always double-escape backslashes in regex character classes within route definitions: `'/users/(?<userId>\\d+)'` instead of `'/users/(?<userId>\d+)'`.
When developing helper functions that rely on `sand.ctx`, ensure they are only called within the scope of a `static Generator Function` action or explicitly pass `this` (the context object) to the helper if it performs asynchronous operations that might lose the `sand.ctx` reference.
Exercise caution when using this package in new projects or critical applications. Be prepared to fork and maintain the code yourself or migrate to a more actively maintained framework. Evaluate the long-term viability and security implications before committing to `sand-http`.
Ensure you are using a Node.js version that supports generator functions (Node.js 6+). If using a transpiler (like Babel), ensure it's configured to handle ES6+ features, including generators.
Verify that `app` is initialized with `new Sand()` and that `Http` is correctly `require`d from `sand-http`. Ensure the `sand` package itself is correctly installed and initialized.
Run `npm install sand-http` in your project directory. Check your `node_modules` folder and ensure `sand-http` is present.
Change `import Http from 'sand-http';` to `const Http = require('sand-http');` and similarly for `Controller` and `Sand`. The package primarily supports CommonJS.