|
3 | 3 | QGIS Server HTTP wrapper |
4 | 4 |
|
5 | 5 | This script launches a QGIS Server listening on port 8081 or on the port |
6 | | -specified on the environment variable QGIS_SERVER_DEFAULT_PORT |
| 6 | +specified on the environment variable QGIS_SERVER_PORT |
| 7 | +QGIS_SERVER_HOST (defaults to 127.0.0.1) |
7 | 8 |
|
8 | 9 | For testing purposes, HTTP Basic can be enabled by setting the following |
9 | 10 | environment variables: |
|
36 | 37 | from qgis.core import QgsApplication |
37 | 38 | from qgis.server import QgsServer |
38 | 39 |
|
39 | | -try: |
40 | | - QGIS_SERVER_DEFAULT_PORT = int(os.environ['QGIS_SERVER_DEFAULT_PORT']) |
41 | | -except KeyError: |
42 | | - QGIS_SERVER_DEFAULT_PORT = 8081 |
| 40 | +QGIS_SERVER_PORT = int(os.environ.get('QGIS_SERVER_PORT', '8081')) |
| 41 | +QGIS_SERVER_HOST = os.environ.get('QGIS_SERVER_HOST', '127.0.0.1') |
43 | 42 |
|
44 | 43 | qgs_app = QgsApplication([], False) |
45 | 44 | qgs_server = QgsServer() |
@@ -101,9 +100,9 @@ def do_POST(self): |
101 | 100 |
|
102 | 101 |
|
103 | 102 | if __name__ == '__main__': |
104 | | - server = HTTPServer(('localhost', QGIS_SERVER_DEFAULT_PORT), Handler) |
105 | | - print('Starting server on localhost:%s, use <Ctrl-C> to stop' % |
106 | | - QGIS_SERVER_DEFAULT_PORT) |
| 103 | + print('Starting server on %s:%s, use <Ctrl-C> to stop' % |
| 104 | + (QGIS_SERVER_HOST, QGIS_SERVER_PORT)) |
| 105 | + server = HTTPServer((QGIS_SERVER_HOST, QGIS_SERVER_PORT), Handler) |
107 | 106 |
|
108 | 107 | def signal_handler(signal, frame): |
109 | 108 | global qgs_app |
|
0 commit comments