diff --git a/compositor.json b/compositor.json new file mode 100644 index 0000000..6237797 --- /dev/null +++ b/compositor.json @@ -0,0 +1,147 @@ +{ + "name": "Kikobeats/svr", + "version": "0.1.4", + "libraries": { + "xv": "^1.1.25" + }, + "title": "", + "branch": "", + "style": { + "name": "Default", + "componentSet": { + "nav": "nav/BasicNav", + "header": "header/BannerHeader", + "article": "article/BasicArticle", + "footer": "footer/BasicFooter" + }, + "fontFamily": "-apple-system, BlinkMacSystemFont, sans-serif", + "fontWeight": 400, + "bold": 600, + "lineHeight": 1.5, + "typeScale": [ + 72, + 48, + 24, + 20, + 16, + 14, + 12 + ], + "monospace": "Menlo, monospace", + "heading": { + "fontFamily": null, + "fontStyle": null, + "fontWeight": 600, + "lineHeight": 1.25, + "textTransform": null, + "letterSpacing": null + }, + "h0": {}, + "h1": {}, + "h2": {}, + "h3": {}, + "h4": {}, + "h5": {}, + "h6": {}, + "alternativeText": {}, + "space": [ + 0, + 8, + 16, + 32, + 48, + 64, + 96 + ], + "layout": { + "maxWidth": 1024, + "centered": false + }, + "colors": { + "text": "#111", + "background": "#fff", + "primary": "#08e", + "secondary": "#059", + "highlight": "#e08", + "border": "#ddd", + "muted": "#eee" + }, + "border": { + "width": 1, + "radius": 2 + }, + "link": {}, + "button": { + "hover": { + "boxShadow": "inset 0 0 0 999px rgba(0, 0, 0, .125)" + } + }, + "input": {}, + "body": { + "margin": 0 + }, + "breakpoints": { + "xs": "@media screen and (max-width:40em)", + "sm": "@media screen and (min-width:40em)", + "md": "@media screen and (min-width:52em)", + "lg": "@media screen and (min-width:64em)" + } + }, + "content": [ + { + "component": "nav", + "links": [ + { + "href": "http://Kikobeats.github.io/svr/", + "text": "Home" + }, + { + "href": "https://github.com/Kikobeats/svr", + "text": "GitHub" + }, + { + "href": "https://npmjs.com/package/svr", + "text": "npm" + } + ] + }, + { + "component": "header", + "heading": "svr", + "subhead": "Hot Module Replacement for HTTP Server", + "children": [ + { + "component": "ui/TweetButton", + "text": "svr: Hot Module Replacement for HTTP Server", + "url": "http://Kikobeats.github.io/svr/" + }, + { + "component": "ui/GithubButton", + "user": "Kikobeats", + "repo": "svr" + } + ], + "text": "v0.4.0" + }, + { + "component": "article", + "metadata": { + "source": "github.readme" + }, + "html": "\n

\n
\n \n
\n

\n\n

\n\n\n\n\n\n

\n
\n

Hot Module replacement (HMR) capabilities for any HTTP Server.

\n
\n

It's similar micro-dev, but out of the box for any framework that use http.Server.listen() interface.

\n

Install

\n
$ npm install svr --save-dev

Usage

\n

Development

\n

The only requirement is define the main file of your server as exported function that follow this interface:

\n
module.exports = (app, express) => {\n/* your awesome code here */\n}

This could be a good start point for a HTTP server:

\n
const isProduction = process.env.NODE_ENV === 'production'\n\nmodule.exports = (app, express) => {\n  /* here you can do whatever you want */\n  app\n    .use(require('helmet')())\n    .use(require('compression')())\n    .use(require('cors')())\n    .use(require('jsendp')())\n    .use(require('express-status-monitor')())\n    .use(bodyParser.urlencoded({ extended: true }))\n    .use(bodyParser.json())\n    .use(require('morgan')(isProduction ? 'combined' : 'dev'))\n    .use(express.static('static'))\n    .disable('x-powered-by')\n\n  app.get('/', async function (req, res) {\n    return res.send('hello world')\n  })\n\n  return app\n}

After that, you need to call svr. We recommend add svr as npm script:

\n
{\n  "scripts": {\n    "dev": "srv"\n  }\n}

Running npm run dev you start your HRM development server:

\n
$ npm start\n\n  ┌───────────────────────────────────────────────────┐\n  │                                                   │\n  │   my-express-api is running!                      │\n  │                                                   │\n  │   • Local:            http://localhost:3000       │\n  │   • On Your Network:  http://192.168.1.106:3000   │\n  │                                                   │\n  └───────────────────────────────────────────────────┘

svr it's assuming main file is called index.js in the current path. Otherwise, you can provide the file path as first argument.

\n

Now whatever file modification in the current directory is listened by the svr automagically:

\n
  ┌───────────────────────────────────────────────────┐\n  │                                                   │\n  │   my-express-api is running!                      │\n  │                                                   │\n  │   • Local:            http://localhost:3000       │\n  │   • On Your Network:  http://192.168.1.106:3000   │\n  │                                                   │\n  └───────────────────────────────────────────────────┘\n\n   ℹ 18:32:42 modified index.js

It takes in consideration your .gitignore files, so it only will reload the right files.

\n

Using svr --watch you can add more files to be watched, but you need to reload the server in any time, just type rs:

\n
  ┌───────────────────────────────────────────────────┐\n  │                                                   │\n  │   my-express-api is running!                      │\n  │                                                   │\n  │   • Local:            http://localhost:3000       │\n  │   • On Your Network:  http://192.168.1.106:3000   │\n  │                                                   │\n  └───────────────────────────────────────────────────┘\n\n   ℹ 18:32:42 modified index.js\n   rs\n   ℹ 18:34:07 restart index.js

Production

\n

svr is oriented for development scenario.

\n

Under production, simply create the boostraping server that you need.

\n

For example, you can take this server.js as production server:

\n
'use strict'\n\nconst express = require('express')\n\nconst app = express()\n\nrequire('./index')(app, express)\n\nconst port = process.env.PORT || process.env.port || 3000\nconst { name } = require('../package.json')\n\napp.listen(port, function () {\n  console.log(`${name} is running at http://localhost:${port}`)\n})

Just add it as npm start script

\n
{\n  "scripts": {\n    "start": "node server.js"\n  }\n}

That's all. You're taking the best of the two worlds: Developer Experience for development and tiny bundle for production.

\n

License

\n

MIT © Kiko Beats.

\n" + }, + { + "component": "footer", + "links": [ + { + "href": "https://github.com/Kikobeats/svr", + "text": "GitHub" + }, + { + "href": "https://github.com/Kikobeats", + "text": "Kikobeats" + } + ] + } + ] +} \ No newline at end of file