Skip to content

Commit

Permalink
Merge pull request #1588 from dhermes/allow-bind-to-local-network
Browse files Browse the repository at this point in the history
Add ability to listen on 0.0.0.0 (instead of localhost)
  • Loading branch information
justinmayer committed Jan 10, 2015
2 parents b72961f + 3d8ceb1 commit 3b22dd4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 25 deletions.
9 changes: 5 additions & 4 deletions pelican/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
except ImportError:
import socketserver # NOQA

PORT = len(sys.argv) == 2 and int(sys.argv[1]) or 8000
PORT = len(sys.argv) in (2, 3) and int(sys.argv[1]) or 8000
SERVER = len(sys.argv) == 3 and sys.argv[2] or ""
SUFFIXES = ['', '.html', '/index.html']


Expand All @@ -38,13 +39,13 @@ def do_GET(self):

socketserver.TCPServer.allow_reuse_address = True
try:
httpd = socketserver.TCPServer(("", PORT), Handler)
httpd = socketserver.TCPServer((SERVER, PORT), Handler)
except OSError as e:
logging.error("Could not listen on port %s", PORT)
logging.error("Could not listen on port %s, server %s", PORT, SERVER)
sys.exit(getattr(e, 'exitcode', 1))


logging.info("Serving at port %s", PORT)
logging.info("Serving at port %s, server %s", PORT, SERVER)
try:
httpd.serve_forever()
except KeyboardInterrupt as e:
Expand Down
51 changes: 30 additions & 21 deletions pelican/tools/templates/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,27 @@ ifeq ($(DEBUG), 1)
endif

help:
@echo 'Makefile for a pelican Web site '
@echo ' '
@echo 'Usage: '
@echo ' make html (re)generate the web site '
@echo ' make clean remove the generated files '
@echo ' make regenerate regenerate files upon modification '
@echo ' make publish generate using production settings '
@echo ' make serve [PORT=8000] serve site at http://localhost:8000'
@echo ' make devserver [PORT=8000] start/restart develop_server.sh '
@echo ' make stopserver stop local server '
@echo ' make ssh_upload upload the web site via SSH '
@echo ' make rsync_upload upload the web site via rsync+ssh '
@echo ' make dropbox_upload upload the web site via Dropbox '
@echo ' make ftp_upload upload the web site via FTP '
@echo ' make s3_upload upload the web site via S3 '
@echo ' make cf_upload upload the web site via Cloud Files'
@echo ' make github upload the web site via gh-pages '
@echo ' '
@echo 'Set the DEBUG variable to 1 to enable debugging, e.g. make DEBUG=1 html'
@echo ' '
@echo 'Makefile for a pelican Web site '
@echo ' '
@echo 'Usage: '
@echo ' make html (re)generate the web site '
@echo ' make clean remove the generated files '
@echo ' make regenerate regenerate files upon modification '
@echo ' make publish generate using production settings '
@echo ' make serve [PORT=8000] serve site at http://localhost:8000'
@echo ' make serve-global [SERVER=0.0.0.0] serve (as root) to $(SERVER):80 '
@echo ' make devserver [PORT=8000] start/restart develop_server.sh '
@echo ' make stopserver stop local server '
@echo ' make ssh_upload upload the web site via SSH '
@echo ' make rsync_upload upload the web site via rsync+ssh '
@echo ' make dropbox_upload upload the web site via Dropbox '
@echo ' make ftp_upload upload the web site via FTP '
@echo ' make s3_upload upload the web site via S3 '
@echo ' make cf_upload upload the web site via Cloud Files'
@echo ' make github upload the web site via gh-pages '
@echo ' '
@echo 'Set the DEBUG variable to 1 to enable debugging, e.g. make DEBUG=1 html '
@echo ' '

html:
$$(PELICAN) $$(INPUTDIR) -o $$(OUTPUTDIR) -s $$(CONFFILE) $$(PELICANOPTS)
Expand All @@ -69,6 +70,14 @@ else
cd $$(OUTPUTDIR) && $(PY) -m pelican.server
endif

serve-global:
ifdef SERVER
cd $$(OUTPUTDIR) && $(PY) -m pelican.server 80 $$(SERVER)
else
cd $$(OUTPUTDIR) && $(PY) -m pelican.server 80 0.0.0.0
endif


devserver:
ifdef PORT
$$(BASEDIR)/develop_server.sh restart $$(PORT)
Expand Down Expand Up @@ -106,4 +115,4 @@ github: publish
ghp-import -m "Generate Pelican site" -b $(GITHUB_PAGES_BRANCH) $$(OUTPUTDIR)
git push origin $(GITHUB_PAGES_BRANCH)

.PHONY: html help clean regenerate serve devserver publish ssh_upload rsync_upload dropbox_upload ftp_upload s3_upload cf_upload github
.PHONY: html help clean regenerate serve serve-global devserver publish ssh_upload rsync_upload dropbox_upload ftp_upload s3_upload cf_upload github

0 comments on commit 3b22dd4

Please sign in to comment.