GithubHelp home page GithubHelp logo

kikobeats / svr Goto Github PK

View Code? Open in Web Editor NEW
71.0 4.0 2.0 8.82 MB

HTTP development server done right

Home Page: https://svr.js.org

License: MIT License

JavaScript 33.61% HTML 7.90% CSS 58.49%
microservice http-server developer-experience livereload

svr's Introduction


svr

svr

Last version Build Status Dependency status Dev Dependencies Status NPM Status

HTTP development server done right.

Features

  • Smart reload, just reloading modified files to do development fast.
  • Reload on demand, after type rs on your terminal.
  • Pretty Errors, making unexpected errors easy to read.
  • Port Selection, supporting detection for already in use ports.
  • Clipboard Support, copying the local address in your clipboard.
  • Debug in Your Network, exposing the process in your local network.

It's similar micro-dev, but compatible with any function that exposes req, res interface (micro, express, koa, hapi, fastify, etc).

Installation

$ npm install svr --save

Usage

Defining entry point

Create a file and export a function that accepts the standard http.IncomingMessage and http.ServerResponse objects, that means, the exported function should be receive req, res:

const express = require('express')
const { Router } = express
const router = Router()

// define middlewares
router.use(require('helmet')())
router.use(require('compression')())
router.use(require('cors')())

// define routes
router.get('/', (req, res) => res.status(204).send())
router.get('/robots.txt', (req, res) => res.status(204).send())
router.get('/favicon.txt', (req, res) => res.status(204).send())

// expose router
module.exports = router

After that, just call svr:

$ svr

svr is assuming you have a main file declared in your package.json in the project directory. Also, you can provide it as first argument:

$ svr index.js

We recommend setup svr as npm script:

{
  "scripts": {
    "dev": "svr"
  }
}

Now, running npm run dev it will be start your HRM development server:

$ npm start

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

You can type svr --help to see all the options.

Smart Reload

When a file is modified in the project directory, svr will reload just the modified file:

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

   ℹ 18:32:42 modified index.js

Also, svr takes into consideration files that can be ignored:

  • Well known files to ignore, like node_modules, .git, etc.
  • .gitignore declarations.
  • ignored field in your package.json.

If you need to add a specific file to ignore, use i or --ignore flag:

$ svr -i .cache -i public

Also, you can use -w or --watch to add more file path to be listened. You can declare:

  • Relative or absolute paths.
  • Glob patterns.

Reload on demand

In any moment you can refresh the process typing rs in the terminal window where svr is running:

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

   ℹ 18:32:42 modified index.js
   rs
   ℹ 18:34:07 restart index.js

Don't use on production

svr is oriented just for development scenarios, not for production.

Under production, simply create the server you need based on your necessities, for example, let's create a bin/server as production server:

#!/usr/bin/env node

'use strict'

const express = require('express')

const app = express()

require('./index')(app, express)

const port = process.env.PORT || process.env.port || 3000
const { name } = require('../package.json')

app.listen(port, function () {
  console.log(`${name} is running at http://localhost:${port}`)
})

You can declare it as npm start script:

{
  "scripts": {
    "dev": "svr",
    "start": "bin/server"
  }
}

That's all.

License

svr © Kiko Beats, released under the MIT License.
Authored and maintained by Kiko Beats with help from contributors.

kikobeats.com · GitHub Kiko Beats · Twitter @Kikobeats

svr's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar gjuchault avatar greenkeeper[bot] avatar kikobeats avatar nea89o avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

svr's Issues

Pull request - Bump lodash from 4.17.10 to 4.17.15 by dependabot[bot]

[zeit/micro-dev]



Bump lodash from 4.17.10 to 4.17.15

By dependabot[bot]



Bumps lodash from 4.17.10 to 4.17.15.

Commits - [`ddfd9b1`](https://ift.tt/2YczIAP) Bump to v4.17.15. - [`b185fce`](https://ift.tt/2Y1jSVk) Rebuild lodash and docs. - [`be87d30`](https://ift.tt/2XDQucp) Bump to v4.17.14. - [`a6fe6b1`](https://ift.tt/30z2MQB) Rebuild lodash and docs. - [`e371828`](https://ift.tt/32ako6O) Bump to v4.17.13. - [`357e899`](https://ift.tt/2NFv3Dd) Rebuild lodash and docs. - [`fd9a062`](https://ift.tt/32akoDQ) Bump to v4.17.12. - [`e77d681`](https://ift.tt/2NTAbUK) Rebuild lodash and docs. - [`629d186`](https://ift.tt/32akpaS) Update OpenJS references. - [`2406eac`](https://ift.tt/2NLIbqz) Fix minified build. - Additional commits viewable in [compare view](https://ift.tt/2YfRTWf)

[![Dependabot compatibility score](https://ift.tt/2Y3WneC) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot ignore this [patch|minor|major] version` will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) - `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language - `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language - `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language - `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language You can disable automated security fix PRs for this repo from the [Security Alerts page](https://ift.tt/2NNF0f1).


November 3, 2019 at 10:23AM
via GitHub https://ift.tt/2pDE3xv

Pull request - Use npm run consistently throughout README by trotzig

[zeit/micro-dev]



Use npm run consistently throughout README

By trotzig



I was reading through the README and noticed that one of the command examples uses yarn run instead of npm run (like all others examples). Not that I have anything against yarn, but it feels better to be consistent about this throughout the document.



January 8, 2019 at 02:15PM

via GitHub http://bit.ly/2H9RNbA

Pull request - allow using micro-dev programmatically by elnygren

[zeit/micro-dev]



allow using micro-dev programmatically

By elnygren



Hi! I wanted to submit an idea I'm using myself with ts-node-dev in a TypeScript + (Apollo) GraphQL project where I use micro as my server library. Problem Using a package.json script such as the following: "start": "ts-node-dev node_modules/.bin/micro-dev -p 4000 src/server.ts", causes the process to crash on syntax errors etc. With micro this can be fixed by programmatically using micro: # package.json "start": "ts-node-dev src/server.ts" # server.ts const server = require('micro')(handler) server.listen(PORT) However, as we all know (https://ift.tt/2L0Cnmi) micro-dev does not support programmatical usage. While many of the features are CLI specific, some are not. Solution With this PR in place, one can do something like: const PORT = process.env.PORT || 4000 if (process.env.NODE_ENV === 'development') { const microDev = require('micro-dev') microDev({ silent: false, limit: '1mb', host: '::', port: PORT })(handler) } else { const server = require('micro')(handler) server.listen(PORT) } Comments * you guys might prefer https://ift.tt/2vMi07Y * the message part breaks DRY but we can clean that up if this direction feels correct * we're not really supporting too many micro-dev features * it might make sense to not call .listen within micro-dev when using the library like this. It would make this PR simpler and the usage a bit cleaner: const server = require('micro')(handler) if (process.env.NODE_ENV === 'development') { server = require('micro-dev')({ silent: false, limit: '1mb'})(handler) } server.listen(PORT) It nothing else, this might act as a good reference for other micro & TypeScript users! Cheers :)



August 16, 2018 at 10:28PM

via GitHub https://ift.tt/2L4jaAw

not reloading for YAML → JSON files

I noted that using config and providing a yaml file, the hot reloading is not working.

I understand why: YAML files compiled into JSON; when a YAML changed, it will be replace from the memory cache of the process but the script for convert it into JSON need to be run again.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

Better error handling

I don't know why, but when the server is listening, if the any error throw from module file, it is not visible at terminal.

I tried a lot of thing (like listen process uncaught exception) but I'm missing something.

Pull request - store request body after logging by maxbeatty

[zeit/micro-dev]



store request body after logging

By maxbeatty



This simple API works with micro but not micro-dev. I believe it has to do with how the logger is reading the body of the request. Without this change, the request hangs using micro-dev. By assigning the parsed JSON to the request, express-graphql can use it later. I understand this is a bit hacky and aimed at express middleware that doesn't take advantage of multiple calls to json. Is there another way to get micro and micro-dev behaving consistently? js const graphqlHTTP = require("express-graphql"); const { buildSchema } = require("graphql"); const jwtAuth = require("micro-jwt-jwks-rsa-auth"); const schema = buildSchema(` type Query { random: Float! } `); const root = { random: () => Math.random() }; const checkJwt = jwtAuth({ jwksRsaConfig: { jwksUri: `https://your-project.auth0.com/.well-known/jwks.json` } }); module.exports = checkJwt(graphqlHTTP({ schema, rootValue: root }));



July 23, 2018 at 07:14AM

via GitHub https://ift.tt/2LFFwJv

Pull request - Show friendly error if 'micro' peer dependency isn't met by bbbrrriiiaaannn

[zeit/micro-dev]



Show friendly error if 'micro' peer dependency isn't met

By bbbrrriiiaaannn



I got too excited to use micro-dev and installed it without regarding the npm WARN about my unmet micro peer dependency. The resulting Cannot find module 'micro/lib' error didn't spark an immediate understanding of the fix. This change validates the availability of micro, and provides a friendlier error if it's missing. I'd meant to use micro-dev to simulate Now V2's routing (starting from this comment)—since this was only in a development context I hadn't made a point of installing micro too. Although my error required a a few willful missteps on my part, my mistakes feel like the sort that other devs getting comfortable with micro-dev could make.



February 20, 2019 at 10:26PM

via GitHub https://ift.tt/2BGUY5a

Pull request - Bump lodash.merge from 4.6.1 to 4.6.2 by dependabot[bot]

[zeit/micro-dev]



Bump lodash.merge from 4.6.1 to 4.6.2

By dependabot[bot]



Bumps lodash.merge from 4.6.1 to 4.6.2.

Commits - See full diff in [compare view](https://ift.tt/2Jsc7Un)

[![Dependabot compatibility score](https://ift.tt/2YNHJcr) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot ignore this [patch|minor|major] version` will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) - `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language - `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language - `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language - `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language You can disable automated security fix PRs for this repo from the [Security Alerts page](https://ift.tt/2NNF0f1).


November 3, 2019 at 10:23AM
via GitHub https://ift.tt/2NccnsP

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because we are using your CI build statuses to figure out when to notify you about breaking changes.

Since we did not receive a CI status on the greenkeeper/initial branch, we assume that you still need to configure it.

If you have already set up a CI for this repository, you might need to check your configuration. Make sure it will run on all new branches. If you don’t want it to run on every branch, you can whitelist branches starting with greenkeeper/.

We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

Once you have installed CI on this repository, you’ll need to re-trigger Greenkeeper’s initial Pull Request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organiszation’s settings page, under Installed GitHub Apps.

Pull request - Bump js-yaml from 3.11.0 to 3.13.1 by dependabot[bot]

[zeit/micro-dev]



Bump js-yaml from 3.11.0 to 3.13.1

By dependabot[bot]



Bumps js-yaml from 3.11.0 to 3.13.1.

Changelog *Sourced from [js-yaml's changelog](https://ift.tt/2ZTwcZn > 3.13.1 / 2019-04-05 > ------------------- > > - Fix possible code execution in (already unsafe) `.load()`, [#480](https://ift.tt/2Fy9SNd). > > > 3.13.0 / 2019-03-20 > ------------------- > > - Security fix: `safeLoad()` can hang when arrays with nested refs > used as key. Now throws exception for nested arrays. [#475](https://ift.tt/2ZWm16r). > > > 3.12.2 / 2019-02-26 > ------------------- > > - Fix `noArrayIndent` option for root level, [#468](https://ift.tt/2Fzby8X). > > > 3.12.1 / 2019-01-05 > ------------------- > > - Added `noArrayIndent` option, [#432](https://ift.tt/2ZWm1mX). > > > 3.12.0 / 2018-06-02 > ------------------- > > - Support arrow functions without a block statement, [#421](https://ift.tt/2SErtbu).
Commits - [`665aadd`](https://ift.tt/2FzbwOn) 3.13.1 released - [`da8ecf2`](https://ift.tt/2ZLMsLL) Browser files rebuild - [`b2f9e88`](https://ift.tt/2FzgbzS) Merge pull request [#480](https://ift.tt/2Fy9SNd) from nodeca/toString - [`e18afbf`](https://ift.tt/2ZKSRqA) Fix possible code execution in (already unsafe) load() - [`9d4ce5e`](https://ift.tt/2Fy1OMu) 3.13.0 released - [`f64c673`](https://ift.tt/2ZO5UYe) Browser files rebuild - [`a567ef3`](https://ift.tt/2FySM1v) Restrict data types for object keys - [`59b6e76`](https://ift.tt/2ZQP76P) Fix test name - [`e4267fc`](https://ift.tt/2FAphfP) 3.12.2 released - [`7231a49`](https://ift.tt/2ZOTbo6) Browser files rebuild - Additional commits viewable in [compare view](https://ift.tt/2PEpAvZ)

[![Dependabot compatibility score](https://ift.tt/36tJsrt) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot ignore this [patch|minor|major] version` will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) - `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language - `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language - `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language - `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language You can disable automated security fix PRs for this repo from the [Security Alerts page](https://ift.tt/2NNF0f1).


November 3, 2019 at 10:23AM
via GitHub https://ift.tt/34rWUdP

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.