Skip to content

Commit d842b41

Browse files
committed
use proxied couchdb except in Panel
1 parent 0316d7e commit d842b41

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

pyttoresque/app/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
from jupyter_server.extension.application import ExtensionApp, ExtensionAppJinjaMixin
99
from tornado.web import addslash
1010
from traitlets import Bool
11-
from subprocess import Popen
12-
from shutil import which
1311

1412
HERE = os.path.dirname(__file__)
1513

@@ -56,10 +54,6 @@ def initialize_handlers(self):
5654

5755
super().initialize_handlers()
5856

59-
binpath = which('couchdb')
60-
if binpath and self.couchdb:
61-
Popen([binpath, '-couch_ini', os.path.join(HERE, "static", "local.ini")])
62-
6357

6458
def main():
6559
Mosaic.launch_instance()

pyttoresque/app/main.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import re
66
import traceback
7+
import urllib.parse as ulp
78
import panel as pn
89
import holoviews as hv
910
import numpy as np
@@ -42,6 +43,15 @@ def __init__(self, **params):
4243
async def _update_spice(self, *events):
4344
try:
4445
url = self.database_url
46+
# if we have a localhost couchdb proxied through Jupyter
47+
# actually use localhost because Jupyter is authenticated
48+
purl = ulp.urlparse(url)
49+
if purl.hostname == "localhost" and purl.path.startswith("/couchdb"):
50+
netloc = f"{purl.username}:{purl.password}@localhost:5984"
51+
path = purl.path[8:]
52+
url = purl._replace(path=path, netloc=netloc).geturl()
53+
self.database_url = url
54+
4555
name = self.schematic
4656
async with netlist.SchematicService(url) as service:
4757
it = service.live_schem_docs(name)

pyttoresque/app/templates/editor.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
<div id="mosaic_editor"></div>
3131
<script>
3232
{% if couchdb %}
33-
window.dburl = "http://admin:admin@localhost:5984"
33+
var url = new URL("/couchdb/", window.location)
34+
url.username = "admin"
35+
url.password = "admin"
36+
window.dburl = url.href
3437
{% endif %}
3538
window.notebookurl = "../../lab"
3639
window.simulatorurl = "../../panel/app"

pyttoresque/app/templates/libman.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
<div id="mosaic_libman"></div>
3131
<script>
3232
{% if couchdb %}
33-
window.dburl = "http://admin:admin@localhost:5984"
33+
var url = new URL("/couchdb/", window.location)
34+
url.username = "admin"
35+
url.password = "admin"
36+
window.dburl = url.href
3437
{% endif %}
3538
</script>
3639
<script src="{{ static_url('common.js') }}"></script>

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
],
5757
'jupyter_serverproxy_servers': [
5858
# name = packagename:function_name
59-
# 'couchdb = pyttoresque.app:setup_couchdb',
59+
'couchdb = pyttoresque.app:setup_couchdb',
6060
'panel = pyttoresque.app:setup_panel',
6161
]
6262
},

0 commit comments

Comments
 (0)