是否可以在瓶子请求中以编程方式获取服务器的 IP 地址?
我需要在请求中返回指向服务器上文件的链接,并且需要知道 IP。Bottle 将在具有不同 IP 的服务器上启动,所有这些 IP 都将成为服务请求。
目前我看起来像这样:
from bottle import *
import json
@get('/file')
def getAFileLink():
# some logic here for the right filename to return
# server runs now on e.g. 10.0.0.1 and 10.10.0.1
# every client should see the IP from the server in the right subnet
return json.dumps({'url': 'http://127.0.0.1:1337/some/file.abc'})
@route('/some/<filename>')
def getStaticFile(filename):
return static_file(filename, root="/srv/static/files")
if __name__ == "__main__":
run(host='0.0.0.0', port=1337)