Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Port on HUG

Is it possible to change the port number on HUG for python? I have the following sample of what I'm trying to do. The API defaults to port 8000 but I want to be able to set it manually.

@hug.post()
def receive_json(request):
    request=str(request)
    print("Hello! Glad you're here!")
    print(request)
    process=os.system("echo "+'"'+request+'"')
like image 783
brandonunited Avatar asked Dec 19 '22 04:12

brandonunited


2 Answers

add at the end of your app.py (or whatever it's name is) file:

hug.API(__name__).http.serve(port=8005)

for serving on port 8005

like image 176
mislavcimpersak Avatar answered Dec 20 '22 20:12

mislavcimpersak


If you are using the hug command line script to start your app, the -p / --port option will get you there, as in hug --port 5000 -f app.py:

$ hug --help
usage: hug [-h] [-v] [-f FILE] [-m MODULE] [-p PORT] [-n] [-ma] [-i INTERVAL]
           [-c COMMAND]

Hug API Development Server

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -f FILE, --file FILE  file
  -m MODULE, --module MODULE
                        module
  -p PORT, --port PORT  A Whole number
  -n, --no_404_documentation
                        Providing any value will set this to true
  -ma, --manual_reload  Providing any value will set this to true
  -i INTERVAL, --interval INTERVAL
                        A Whole number
  -c COMMAND, --command COMMAND
                        command
like image 34
Dirk Avatar answered Dec 20 '22 19:12

Dirk