{"library":"sand-http","title":"Sand HTTP Application Server","description":"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.","language":"javascript","status":"abandoned","last_verified":"Thu Apr 23","install":{"commands":["npm install sand-http"],"cli":null},"imports":["const Http = require('sand-http');","const Controller = require('sand-http').Controller;","const Sand = require('sand');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"\"use strict\";\n\nconst Http = require('sand-http');\nconst Sand = require('sand');\nconst path = require('path');\nconst fs = require('fs');\n\n// Create dummy config and controller files for quickstart\nconst configDir = path.join(__dirname, 'config');\nconst controllersDir = path.join(__dirname, 'controllers');\nconst viewsDir = path.join(__dirname, 'views');\n\nif (!fs.existsSync(configDir)) fs.mkdirSync(configDir);\nif (!fs.existsSync(controllersDir)) fs.mkdirSync(controllersDir);\nif (!fs.existsSync(viewsDir)) fs.mkdirSync(viewsDir);\n\nfs.writeFileSync(path.join(configDir, 'routes.js'), `\nmodule.exports = {\n\t'/': 'MyController.index'\n};\n`);\n\nfs.writeFileSync(path.join(configDir, 'http.js'), `\nmodule.exports = {\n\tall: {\n\t\tport: 3000\n\t}\n};\n`);\n\nfs.writeFileSync(path.join(controllersDir, 'MyController.js'), `\n\"use strict\";\n\nconst Controller = require('sand-http').Controller;\n\nclass MyController extends Controller {\n\tstatic *index() {\n\t\tthis.res.writeHead(200, {'Content-Type': 'text/plain'});\n\t\tthis.res.end('Hello from Sand HTTP!');\n\t}\n}\n\nmodule.exports = MyController;\n`);\n\nconsole.log('Starting Sand HTTP server on port 3000...');\nlet app = new Sand({log: '*'});\napp.use(Http);\napp.start();\n\nprocess.on('SIGINT', () => {\n  console.log('Stopping Sand HTTP server...');\n  app.shutdown();\n  process.exit();\n});\n","lang":"javascript","description":"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/`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}