{"id":22059291,"url":"https://github.com/opentable/spur-web","last_synced_at":"2025-05-12T19:44:55.395Z","repository":{"id":26577373,"uuid":"30031695","full_name":"opentable/spur-web","owner":"opentable","description":"Common node modules and express middleware that are designed to be the boilerplate of a node web app. Extends the 'spur-common' NPM module.","archived":false,"fork":false,"pushed_at":"2024-04-11T00:32:40.000Z","size":454,"stargazers_count":4,"open_issues_count":2,"forks_count":7,"subscribers_count":37,"default_branch":"main","last_synced_at":"2024-04-29T21:18:38.121Z","etag":null,"topics":["nodejs","npm-package","renovate","spur","spur-framework"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/opentable.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-01-29T17:17:53.000Z","updated_at":"2024-08-08T06:28:31.360Z","dependencies_parsed_at":"2023-12-29T11:31:04.213Z","dependency_job_id":"c37b606d-954d-4757-8743-482a10d6d08e","html_url":"https://github.com/opentable/spur-web","commit_stats":{"total_commits":95,"total_committers":8,"mean_commits":11.875,"dds":0.6421052631578947,"last_synced_commit":"c30f8d44e23a297422c7246a5266b7b75ad9ad89"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentable%2Fspur-web","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentable%2Fspur-web/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentable%2Fspur-web/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opentable%2Fspur-web/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opentable","download_url":"https://codeload.github.com/opentable/spur-web/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227383430,"owners_count":17772235,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nodejs","npm-package","renovate","spur","spur-framework"],"created_at":"2024-11-30T17:27:52.734Z","updated_at":"2024-11-30T17:27:53.247Z","avatar_url":"https://github.com/opentable.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://opentable.github.io/spur/logos/Spur-Web.png?rand=1\" width=\"100%\" alt=\"Spur: Web\" /\u003e\n\nCommon node modules and express middleware that are designed to be the boilerplate of a node web app.\n\n[![NPM Version][npm-version-image]][npm-url]\n[![NPM Install Size][npm-install-size-image]][npm-install-size-url]\n[![NPM Downloads][npm-downloads-image]][npm-downloads-url]\n\n# About the Spur Framework\n\nThe Spur Framework is a collection of commonly used Node.JS libraries used to create common application types with shared libraries.\n\n[Visit NPMJS.org for a full list of Spur Framework libraries](https://www.npmjs.com/browse/keyword/spur-framework) \u003e\u003e\n\n# Topics\n\n- [Quick start](#quick-start)\n  - [Usage](#usage)\n- [Available dependencies in injector](#available-dependencies-in-injector)\n- [Contributing](#contributing)\n- [License](#license)\n\n# Quick start\n\n## Installing\n\n`Dependencies:`\n```shell\n$ npm install --save spur-ioc spur-common spur-config\n```\n\n`Module:`\n```shell\n$ npm install --save spur-web\n```\n\n**Note:** The example code below expects that you are using Node 6. We follow the active [Node LTS schedule](https://github.com/nodejs/LTS).\n\n## Usage\n\n#### `src/config/*`\n\nFor an example of the configuration, please take a look at this example: [example/src/config/](example/src/config).\n\n#### `src/injector.js`\n\n```javascript\nconst path = require('path');\nconst spur = require('spur-ioc');\nconst spurCommon = require('spur-common');\nconst registerConfig = require('spur-common/registerConfig');\nconst spurWeb = require('spur-web');\n\nmodule.exports = function () {\n  const ioc = spur.create('example');\n\n  // Register configuration\n  registerConfig(ioc, path.join(__dirname, './config'));\n\n  ioc.merge(spurCommon());\n  ioc.merge(spurWeb());\n\n  // register folders in your project to be auto-injected\n  ioc.registerFolders(__dirname, [\n    'controllers/',\n    'runtime/'\n  ]);\n\n  return ioc;\n};\n```\n\n#### `src/runtime/WebServer.js`\n\n```javascript\nmodule.exports = function (BaseWebServer, path) {\n  class WebServer extends BaseWebServer {\n\n    // Add additional changes to the middleware by overriding the method\n    registerDefaultMiddleware() {\n      super.registerDefaultMiddleware();\n    }\n  }\n\n  // Assure there is just one instance\n  return new WebServer();\n};\n```\n\n#### `src/controllers/HelloController.js`\n\nFiles ending in `*Controller.js` are auto registered as controllers.\n\n```javascript\nmodule.exports = function (BaseController) {\n  class HelloController extends BaseController {\n\n    configure(app) {\n      super.configure(app);\n\n      app.get('/', this.getRoot.bind(this));\n      app.get('/hello', this.getHello.bind(this));\n    }\n\n    getRoot(req, res) {\n      res.status(200).send('This is the root page defined in HelloController.js.');\n    }\n\n    getHello(req, res) {\n      res.send('hello');\n    }\n  }\n\n  return new HelloController();\n};\n```\n\n#### `start.js`\n\n```javascript\nconst injector = require('./src/injector');\n\n// IMPORTANT: The callback needs to be a function call vs. using a fat-arrow block. Fat-arrow is not supported yet.\ninjector().inject(function (UncaughtHandler, WebServer, Logger, config, configLoader, nodeProcess) {\n  UncaughtHandler.listen();\n\n  Logger.info(`NODE_ENV: ${nodeProcess.env.NODE_ENV}`);\n  Logger.info(`PORT: ${config.Port}`);\n  Logger.info(`CONFIG: ${configLoader.configName}`);\n\n  WebServer.start()\n    .then(() =\u003e {\n      // Execute other logic after the server has started\n    });\n});\n```\n\n### Running example\n\n```shell\n$ npm start\n```\n\n# Available dependencies in injector\n\nTo see the latest list of the default dependencies that are injected, check out the [injector.js](src/injector.js) file. Here is a short list of of all of the dependencies available:\n\n### Libraries\n\nList of external dependencies used and exposed by spur-web. They can be found at npmjs.org using their original names.\n\n| Name               | Original Module Name                                             |\n| :----              | :----                                                            |\n| **express**        | [express](https://www.npmjs.org/package/express)                 |\n| **expressDevice**  | [express-device](https://www.npmjs.org/package/express-device)   |\n| **methodOverride** | [method-override](https://www.npmjs.org/package/method-override) |\n| **cookieParser**   | [cookie-parser](https://www.npmjs.org/package/cookie-parser)     |\n| **bodyParser**     | [body-parser](https://www.npmjs.org/package/body-parser)         |\n| **expressWinston** | [express-winston](https://www.npmjs.org/package/express-winston) |\n\n### Local dependencies\n\nAll of the files under the `src/` directory are made available when this module is merged into another injector. The following list are the notable dependencies available.\n\n#### Reusable\n\n| Name                       | Source                                          | Description                                                                                                 |\n| :----                      | :----                                           | :----                                                                                                       |\n| **BaseController**         | [code](src/webserver/BaseController.js)         | A base class in order to be able to identify all of the controllers derived from it.                        |\n| **BaseWebServer**          | [code](src/webserver/BaseWebServer.js)          | A base web server that sets all of the middleware mentioned here.                                           |\n| **ControllerRegistration** | [code](src/webserver/ControllerRegistration.js) | Registers all of the controllers based on the BaseController type and also files that end with `Controller` |\n| **BaseMiddleware**         | [code](src/middleware/BaseMiddleware.js)        | A base class in order to be able to identify all of the middleware derived from it.                         |\n\n#### Used internally, but can be used/replaced\n\n| Name                                | Source                                                    | Description                                                                                                                 |\n| :----                               | :----                                                     | :----                                                                                                                       |\n| **HtmlErrorRender**                 | [code](src/handlers/HtmlErrorRender.js)                   | Sets basic error rendering for uncaught errors.                                                                             |\n| **DefaultMiddleware**               | [code](src/middleware/DefaultMiddleware.js)               | Registers default express middleware: cookie parser, and body parser                                                        |\n| **ErrorMiddleware**                 | [code](src/middleware/ErrorMiddleware.js)                 | Adds error handling for unhandled errors for requests.                                                                      |\n| **NoCacheMiddleware**               | [code](src/middleware/NoCacheMiddleware.js)               | Middleware for no cache headers                                                                                             |\n| **PromiseMiddleware**               | [code](src/middleware/PromiseMiddleware.js)               | Extends the response object with functionality to be used through promises. It unwraps promises as they are being resolved. |\n| **WinstonRequestLoggingMiddleware** | [code](src/middleware/WinstonRequestLoggingMiddleware.js) | Winston middleware for logging every request to the console log.                                                            |\n\n# Contributing\n\n## We accept pull requests\n\nPlease send in pull requests and they will be reviewed in a timely manner. Please review this [generic guide to submitting a good pull requests](https://github.com/blog/1943-how-to-write-the-perfect-pull-request). The only things we ask in addition are the following:\n\n- Please submit small pull requests\n- Provide a good description of the changes\n- Code changes must include tests\n- Be nice to each other in comments. :innocent:\n\n## Style guide\n\nThe majority of the settings are controlled using an [EditorConfig](.editorconfig) configuration file. To use it [please download a plugin](http://editorconfig.org/#download) for your editor of choice.\n\n## All tests should pass\n\nTo run the test suite, first install the dependencies, then run `npm test`\n\n```shell\n$ npm install\n$ npm test\n```\n\n# License\n\n[MIT](LICENSE)\n\n[npm-downloads-image]: https://badgen.net/npm/dm/spur-web\n[npm-downloads-url]: https://npmcharts.com/compare/spur-web?minimal=true\n[npm-install-size-image]: https://badgen.net/packagephobia/install/spur-web\n[npm-install-size-url]: https://packagephobia.com/result?p=spur-web\n[npm-url]: https://npmjs.org/package/spur-web\n[npm-version-image]: https://badgen.net/npm/v/spur-web\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentable%2Fspur-web","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopentable%2Fspur-web","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopentable%2Fspur-web/lists"}