Giter Club home page Giter Club logo

servedir's Introduction

servedir

servedir is a simple Node web server for offline development and testing: running servedir from a directory will create a quick local web server. servedir is useful for developing scripts that require a standard web environment and can't use the file:// protocol.

The annotated source code is included in the docs/ folder.

Installation

Check out a working copy of the source code with Git, or install servedir via npm. The latter will also install servedir into the system's bin path.

$ git clone git://github.com/remy/servedir.git
$ npm install servedir -g

Usage

servedir [path] [port]

  • path - The location to serve files and directories from. Defaults to the current working directory.
  • port - The port number. Default to 8000.

If no port is given, it'll try to find the next free port from 8000 upwards.

Mocked router

To create a mock router, create a routes.json file in the current working directory, and servedir will respond with your data.

For example:

{
  "GET /foo/:id": {
    "id": "{{id}}",
    "title": "Awesome stuff"
  },
  "POST /ok": {
    "success": true
  },
  "POST /fail": {
    "success": true
  }
}

Now requests to those URLs will respond with JSON for the mocked endpoints.

Example

$ servedir
$ servedir 8001
$ servedir ~/Documents/example
$ servedir ~/Documents/example 8001

Contributors

servedir's People

Contributors

evanw avatar grahamb avatar mathiasbynens avatar remy 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

Watchers

 avatar  avatar  avatar  avatar  avatar

servedir's Issues

v0.2.0: Custom events

Subclassing http.Server will allow developers to attach custom events for serving files and directories, logging requests, and handling errors.

v0.2.0: Add support for using `servedir` as a module

Python's SimpleHTTPServer can be used as both a module and a command-line utility. servedir v0.1.9 added partial support for this, but v0.2.0 could expose a subclass of http.Server, allowing developers to create simple servers from their unit testing files. This will also add support for custom events, which can be used to simplify the process of serving files and directories.

v0.2.0: `servedir.encode`

The native encodeURIComponent and decodeURIComponent functions don't fully support URL-encoding. servedir currently uses a simple encoding routine for creating directory listings, which could be exposed as servedir.encode.

v0.2.0: `servedir.mime`

servedir currently determines a file's MIME type using its extension. This could be extracted and exposed as servedir.mime(path).

v0.2.0: log requests

Python’s SimpleHTTPServer logs every request back to the console, which is particularly useful to detect requests that result in 404 errors. It would be nice to have this kind of functionality in servedir, maybe with an option to filter the log so that it only shows errors.

A typo in instructions

Hi Remy!

Great utility, thank you!

However, I've found a typo in Installation section of README.md.

Where it says:
$ git clone git://github.com/rem/servedir.git

it should be remy instead of rem:
$ git clone git://github.com/remy/servedir.git

Not a big deal by may confuse beginners ;)

Cheers,
Miro

It's not serving index.html automatically

Hi there,

Thanks for servedir.

Is it just me, or other people also don't get index.html served automatically?

When I servedir is running on a folder, when I gor to the address, it shows the list of files of the folder.

Ability to stop servedir instance from command line

Wanted: Ability to stop servedir instance from command line, with the same basic input combos as the command to start them. For example:

  • node servedir --stop
  • node servedir --stop ./
  • node servedir --stop 8080
  • node servedir --stop ./ 8080

Not 100% sure what the last one would do:

  1. Stop the servedir instance only if it matched both inputs
  2. Stop the servedir instances (possibly 2+) that match each individual input

Please consider it. Thanks!

status of this project?

Looks like the last commit was in early 2018. Is this project still maintained or should it be considered EOL? @remy

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.