- this.server = new static_server({ port: 9999, rootPath: workdir });
- await this.server.start();
- console.log(`server running on port ${this.server.port}`);
+ this.static_http_server = new static_server({ port: static_port, rootPath: workdir });
+ await this.static_http_server.start();
+ console.log(`static server serving ${workdir} directory running on port ${static_port}`);
+
+ if (use_proxy) {
+ // https://github.com/http-party/node-http-proxy#readme
+ const proxy = await httpProxy.createProxy({ changeOrigin: true, followRedirects: true });
+ this.proxy = proxy;
+ console.log('proxy started');
+
+ this.proxy_server = await http.createServer((req, res) => {
+ // identify if the requests should be served by the (remote) API or static webserver
+ let api_url_match = req.url.match(/\/(\w+\.php)/);
+
+ let target = api_url_match
+ ? 'http://nominatim.openstreetmap.org/' + api_url_match[1]
+ : 'http://localhost:' + static_port;
+
+ // console.log(`http proxy ${req.url} => ${target + req.url}`)
+ return proxy.web(req, res, { target: target });
+ }).listen(testing_port);
+ console.log(`proxy server started on port ${testing_port}`);
+ }
+