Quantcast
Channel: CodeSection,代码区,Python开发技术文章_教程 - CodeSec
Viewing all articles
Browse latest Browse all 9596

Simple file server to serve current directory

$
0
0

I'm looking for a dead simple bin that I can launch up in the shell and have it serve the current directory (preferably not ..), with maybe a -p for specifying port. As it should be a development server, it should by default allow connections from localhost only, maybe with an option to specify otherwise. The simpler, the better.

Not sure which tags to use here.

Problem courtesy of: Reactormonk

Solution python -m SimpleHTTPServer

or

python -m SimpleHTTPServer 80

if you don't want to use the default port 8000. See the docs .

Solution courtesy of: David Pope

Discussion

There is the Perl app App::HTTPThis or I have often used a tiny Mojolicious server to do this. See my blog post from a while back.

Make a file called say server.pl . Put this in it.

#!/usr/bin/env perl use Mojolicious::Lite; use Cwd; app->static->paths->[0] = getcwd; any '/' => sub { shift->render_static('index.html'); }; app->start;

Install Mojolicious: curl get.mojolicio.us | sh and then run morbo server.pl .

Should work, and you can tweak the script if you need to.

Discussion courtesy of: Joel Berger

For Node, there's http-server :

$ npm install -g http-server $ http-server Downloads -a localhost -p 8080 Starting up http-server, serving Downloads on port: 8080 Hit CTRL-C to stop the server

Python has:

Python 3 : python -m http.server 8080 Python 2 : python -m SimpleHTTPServer 8080

Note that these two allow all connections (not just from localhost ). Sadly, there isn't a simple way to change the address.

Discussion courtesy of: Blender

Using Twisted Web :

twistd --pidfile= -n web --path . --port 8080

--pidfile= disables the PID file. Without it a twistd.pid file will be created in the current directory. You can also use --pidfile '' .

Discussion courtesy of: Cristian Ciupitu

This recipe can be found in it's original form on Stack Over Flow .


Viewing all articles
Browse latest Browse all 9596

Trending Articles