GithubHelp home page GithubHelp logo

serve's Introduction

serve

Simple 5 minute command-line file / directory server built with connect, inspired by nodejitsu's http-server to show off the simplicity and flexibility of connect as a modular server.

Installation

$ npm install -g tj/serve

Note: the "serve" name on NPM (as of 2.x) refers to https://github.com/zeit/serve.

Usage

Usage: serve [options] [dir]

Options:

  -h, --help                output usage information
  -V, --version             output the version number
  -o, --open                opens a browser window to this server
  -a, --auth <user>:<pass>  specify basic auth credentials
  -F, --format <fmt>        specify the log format string
  -p, --port <port>         specify the port [3000]
  -r, --root <root>         specify the root directory []
      --https-port <port>   specify the port [3443]
  -H, --hidden              enable hidden file serving
  -S, --no-stylus           disable stylus rendering
  -J, --no-jade             disable jade rendering
      --no-less             disable less css rendering
  -I, --no-icons            disable icons
  -L, --no-logs             disable request logging
  -D, --no-dirs             disable directory serving
  -f, --favicon <path>      serve the given favicon
  -C, --cors                allows cross origin access serving
  -s, --https               also serve over https
      --key                 key file path for https
      --cert                certificate file for https
      --ca                  CA certificate file for https
      --compress            gzip or deflate the response
      --exec <cmd>          execute command on each request

Examples

HTTP Accept support built into connect.directory():

 $ curl http://local:3000/ -H "Accept: text/plain"
 bin
 History.md
 node_modules
 package.json
 Readme.md

Requesting a file:

$ curl http://local:3000/Readme.md

 # serve
 ...

Requesting JSON for the directory listing:

$ curl http://local:3000/ -H "Accept: application/json"
["bin","History.md","node_modules","package.json","Readme.md"]

Directory listing served by connect's connect.directory() middleware.

directory listings

License

(The MIT License)

Copyright (c) 2011 TJ Holowaychuk <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

serve's People

Contributors

adrianhelvik avatar amio avatar btmills avatar chuckpreslar avatar johnbonesnj avatar jsprds avatar lbebber avatar rauchg avatar scttnlsn avatar slexaxton avatar stevemao avatar thom4parisot avatar tj avatar tusharmath avatar ymichael 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

serve's Issues

Support custom root route

Hi,

It would be convenient if it was possible to set up a server so that rather than pointing at / by default, it could point to something else (like /foo). We could call this option -R (--root).

Having this option would make it very easy for me to test certain paths generated by a static generator of mine. I'm not sure if there's an utility beyond that, though.

add file metadata

More file metadata would be great.Serve could be a great tool to develop simple REST JSON based tools. For example with QT QML.

  • File Extension
  • File Create Date
  • File Modify Date
  • File Accessed Date
  • File Writeable True/False
  • File Size (could be slow)

Update on NPM

Installing from git works, but installing from NPM still complains about out of date less-middleware usage. Please update!

File structure not navigatable on Firefox on Windows

Hey,

thanks for serve, it's a really cool tool! Just found one issue recently:

In Firefox on windows, links in the file structure view don't have their backslashes correctly replaced with slashes. The file view is not usable then.

To reproduce:

  • use Firefox (I use 40) on Windows to access serve via http
  • navigate into a directory from root (/build in my case)
  • a '' is prepended to the URL (http://localhost:8000/%5Cbuild)
  • navigate into a subdirectory in the new directory (in my case /build/dp)
  • '' sneaks into the URL again, but this time escaped: http://localhost:8000/\build/\\build\dp\
  • the server replies with an error message because the URL is not valid

unbenannt

Update dependencies

Connect 2.x is extremely outdated and there are other security concerns. Serve could even be using Express now.

(+) 8 vulnerabilities found
┌───────────────┬───────────────────────────────────────────────────────┐
│               │ methodOverride Middleware Reflected Cross-Site Scrip… │
├───────────────┼───────────────────────────────────────────────────────┤
│ Name          │ connect                                               │
├───────────────┼───────────────────────────────────────────────────────┤
│ Installed     │ 2.3.9                                                 │
├───────────────┼───────────────────────────────────────────────────────┤
│ Vulnerable    │ <=2.8.0                                               │
├───────────────┼───────────────────────────────────────────────────────┤
│ Patched       │ >=2.8.1                                               │
├───────────────┼───────────────────────────────────────────────────────┤
│ Path          │ serve > connect                                       │
├───────────────┼───────────────────────────────────────────────────────┤
│ More Info     │ https://nodesecurity.io/advisories/3                  │
└───────────────┴───────────────────────────────────────────────────────┘
┌───────────────┬───────────────────────────────────────────────────────┐
│               │ Denial-of-Service Extended Event Loop Blocking        │
├───────────────┼───────────────────────────────────────────────────────┤
│ Name          │ qs                                                    │
├───────────────┼───────────────────────────────────────────────────────┤
│ Installed     │ 0.4.2                                                 │
├───────────────┼───────────────────────────────────────────────────────┤
│ Vulnerable    │ <1.0.0                                                │
├───────────────┼───────────────────────────────────────────────────────┤
│ Patched       │ >= 1.x                                                │
├───────────────┼───────────────────────────────────────────────────────┤
│ Path          │ connect > qs                                          │
├───────────────┼───────────────────────────────────────────────────────┤
│ More Info     │ https://nodesecurity.io/advisories/28                 │
└───────────────┴───────────────────────────────────────────────────────┘
┌───────────────┬───────────────────────────────────────────────────────┐
│               │ Denial-of-Service Memory Exhaustion                   │
├───────────────┼───────────────────────────────────────────────────────┤
│ Name          │ qs                                                    │
├───────────────┼───────────────────────────────────────────────────────┤
│ Installed     │ 0.4.2                                                 │
├───────────────┼───────────────────────────────────────────────────────┤
│ Vulnerable    │ <1.0.0                                                │
├───────────────┼───────────────────────────────────────────────────────┤
│ Patched       │ >= 1.x                                                │
├───────────────┼───────────────────────────────────────────────────────┤
│ Path          │ connect > qs                                          │
├───────────────┼───────────────────────────────────────────────────────┤
│ More Info     │ https://nodesecurity.io/advisories/29                 │
└───────────────┴───────────────────────────────────────────────────────┘
┌───────────────┬───────────────────────────────────────────────────────┐
│               │ Root Path Disclosure                                  │
├───────────────┼───────────────────────────────────────────────────────┤
│ Name          │ send                                                  │
├───────────────┼───────────────────────────────────────────────────────┤
│ Installed     │ 0.0.3                                                 │
├───────────────┼───────────────────────────────────────────────────────┤
│ Vulnerable    │ <0.11.1                                               │
├───────────────┼───────────────────────────────────────────────────────┤
│ Patched       │ >=0.11.1                                              │
├───────────────┼───────────────────────────────────────────────────────┤
│ Path          │ connect > send                                        │
├───────────────┼───────────────────────────────────────────────────────┤
│ More Info     │ https://nodesecurity.io/advisories/56                 │
└───────────────┴───────────────────────────────────────────────────────┘
┌───────────────┬───────────────────────────────────────────────────────┐
│               │ Directory Traversal                                   │
├───────────────┼───────────────────────────────────────────────────────┤
│ Name          │ send                                                  │
├───────────────┼───────────────────────────────────────────────────────┤
│ Installed     │ 0.0.3                                                 │
├───────────────┼───────────────────────────────────────────────────────┤
│ Vulnerable    │ < 0.8.4                                               │
├───────────────┼───────────────────────────────────────────────────────┤
│ Patched       │ >= 0.8.4                                              │
├───────────────┼───────────────────────────────────────────────────────┤
│ Path          │ connect > send                                        │
├───────────────┼───────────────────────────────────────────────────────┤
│ More Info     │ https://nodesecurity.io/advisories/32                 │
└───────────────┴───────────────────────────────────────────────────────┘
┌───────────────┬───────────────────────────────────────────────────────┐
│               │ Regular Expression Denial of Service                  │
├───────────────┼───────────────────────────────────────────────────────┤
│ Name          │ uglify-js                                             │
├───────────────┼───────────────────────────────────────────────────────┤
│ Installed     │ 2.5.0                                                 │
├───────────────┼───────────────────────────────────────────────────────┤
│ Vulnerable    │ All                                                   │
├───────────────┼───────────────────────────────────────────────────────┤
│ Patched       │ None                                                  │
├───────────────┼───────────────────────────────────────────────────────┤
│ Path          │ jade > uglify-js                                      │
├───────────────┼───────────────────────────────────────────────────────┤
│ More Info     │ https://nodesecurity.io/advisories/48                 │
└───────────────┴───────────────────────────────────────────────────────┘
┌───────────────┬───────────────────────────────────────────────────────┐
│               │ Regular Expression Denial of Service                  │
├───────────────┼───────────────────────────────────────────────────────┤
│ Name          │ uglify-js                                             │
├───────────────┼───────────────────────────────────────────────────────┤
│ Installed     │ 2.2.5                                                 │
├───────────────┼───────────────────────────────────────────────────────┤
│ Vulnerable    │ All                                                   │
├───────────────┼───────────────────────────────────────────────────────┤
│ Patched       │ None                                                  │
├───────────────┼───────────────────────────────────────────────────────┤
│ Path          │ jade > transformers > uglify-js                       │
├───────────────┼───────────────────────────────────────────────────────┤
│ More Info     │ https://nodesecurity.io/advisories/48                 │
└───────────────┴───────────────────────────────────────────────────────┘
┌───────────────┬───────────────────────────────────────────────────────┐
│               │ Incorrect Handling of Non-Boolean Comparisons During… │
├───────────────┼───────────────────────────────────────────────────────┤
│ Name          │ uglify-js                                             │
├───────────────┼───────────────────────────────────────────────────────┤
│ Installed     │ 2.2.5                                                 │
├───────────────┼───────────────────────────────────────────────────────┤
│ Vulnerable    │ <= 2.4.23                                             │
├───────────────┼───────────────────────────────────────────────────────┤
│ Patched       │ >= 2.4.24                                             │
├───────────────┼───────────────────────────────────────────────────────┤
│ Path          │ jade > transformers > uglify-js                       │
├───────────────┼───────────────────────────────────────────────────────┤
│ More Info     │ https://nodesecurity.io/advisories/39                 │
└───────────────┴───────────────────────────────────────────────────────┘

release & publish?

current version in npm is unusable

$ npm uninstall serve
unbuild [email protected]
stephenmathieson at 0x6D746873 in ~/repos/components/rndid on master*
$ npm install serve@latest
[ . . . ]
$ node_modules/.bin/serve .

/Users/stephenmathieson/repos/components/rndid/node_modules/serve/node_modules/less-middleware/lib/middleware.js:50
    throw new Error('Please update your less-middleware usage: http://goo.gl/Y
          ^
Error: Please update your less-middleware usage: http://goo.gl/YnK8p0
    at module.exports.less.middleware (/Users/stephenmathieson/repos/components/rndid/node_modules/serve/node_modules/less-middleware/lib/middleware.js:50:11)
    at Object.<anonymous> (/Users/stephenmathieson/repos/components/rndid/node_modules/serve/bin/serve:81:14)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3

Is this project still maintained?

Hi TJ, I'm a fan of serve. It doesn't look like it's maintained anymore and would love to adopt the project to clean up/add the features

port NaN

port argument allows NaN. Example:

serve -p foobar

Perhaps should be filed upstream with commander.

gzip compression

Hi!

It's pretty cool to prototype quick stuff relying on HTTP without having to build an "app".

Do you have plans to support gzip compression?
The middleware PR should do the trick though, as it's already a connect middleware.

Thanks :-)

Process SSI tags

Can an option be added to process Apache-style serverside includes? I think for most folks, a basic implementation would suffice. But any type of includes-system really, would be a great little thing to have.

Example:

<!--#include virtual="inc/footer.html"-->

This would be relative to the file being processed.

backgrounded serve process stays open when terminal is closed

not actually sure if this is my OS or serve, but I'm not sure if you've noticed but here are the steps:

  1. Close the terminal window while a background serve process is running.
  2. Go to the address of that background process. It should open back up again
  3. Reload the page. The background process should shutdown.

This is annoying because it doesn't allow you to reclaim ports right away.

Ugly console output if port is already in use

Running serve twice prints

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: listen EADDRINUSE
    at errnoException (net.js:901:11)
    at Server._listen2 (net.js:1039:14)
    at listen (net.js:1061:10)
    at Server.listen (net.js:1127:5)
    at Function.app.listen (D:\dev\lng\JavaScript\node.js\node-globals\node_modules\serve\node_modules\connect\lib\proto.js:229:24)
    at Object.<anonymous> (D:\dev\lng\JavaScript\node.js\node-globals\node_modules\serve\bin\serve:113:8)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

to the console the second time. Nicer output would be apreciated.

Support 0.6.0

I don't want to cause more work for you but, serve and a few others are not supporting 0.6.0. I know it was just released; take your time. I just wanted to create issues. If you want I can fork and help with the migrations.

Nope, this package do not work

vagrant@precise32:~/repos/nemobile$ sudo npm install serve   
npm WARN package.json [email protected] No description
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No README data
npm WARN package.json [email protected] No license field.
npm WARN prefer global [email protected] should be installed with -g
[email protected] node_modules/serve
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected])
vagrant@precise32:~/repos$ node serve
module.js:338
    throw err;
          ^
Error: Cannot find module '/home/vagrant/repos/serve'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

CoffeeScript

Can we get some input on whether CoffeeScript isn't going to be added or just hasn't been done correctly yet? There are two pull requests right now (#11 and #12) that attempt to add CoffeeScript, though I could see potential issues with each - nonstandard version and synchronous I/O, respectively. The version I've been using locally (and have pushed to my fork at btmills/serve):

  • uses the standard CoffeeScript compiler
  • reads the source file asynchronously
  • detects .coffee or .js extensions (ex: <script src="foo.js"></script> will get the compiled version of foo.coffee)

I didn't want to send yet another pull request for the same feature until there was some feedback on what's really needed, though I think CoffeeScript support is definitely worth adding.

Support Cache Busting

How

  1. Create a function etag. It takes a url and appends the digest to the path.
  2. Inject into JADE as local function and as a JS function.
  3. Developer can use it on the client side where ever required.

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.