Fork me on GitHub
#portal
<
2023-07-25
>
gdubs04:07:08

How do I start/open the vs-code hosted portal so I can hit it from a shadow-cljs browser environment?

gdubs04:07:34

I imagine I could call portal.api/open from a joyride script?

gdubs04:07:04

Similar question except I'm using browser instead of node: https://clojurians.slack.com/archives/C0185BFLLSE/p1661026662799939

gdubs05:07:33

Ran across https://github.com/djblue/portal/blob/098062b5ae23bbdb027654b887f874c0eb7cce88/src/portal/shadow/remote.clj which starts a server. Pretty neat. But when I submit data to the server, where does it go?

djblue18:07:09

Hitting the /submit is equivalent to calling portal.api/submit

djblue18:07:14

Which gets conj'd into this private list https://github.com/djblue/portal/blob/master/src/portal/runtime.cljc#L198-L200 which is the default value portal will inspect

gdubs18:07:54

> But when I submit data to the server, where does it go? Sorry, I should've been clearer. I recognize that it goes to to the running server, but how do I view it? Can I 'open' a portal that also attaches to the same server that shadow-cljs started?

djblue18:07:54

Yeah, you can call portal.api/open on the jvm which shadow-cljs is running 👍

djblue18:07:12

And you can pass all the normal options to open, like {:launcher :vs-code}

gdubs18:07:31

Cool. Do I need to pass it special options so it associates with the already-started server and doesn't start a new server?

djblue18:07:23

Nope, the server will only start if not already started

👍 2
gdubs18:07:38

Is that only true of the JVM that runs shadow is the same JVM that I use to call portal.api/open?

👍 2
djblue18:07:01

Yup, although you can submit to another jvm which has portal as long as you coordinate which port to use for /submit

djblue18:07:32

You can start/open portal with a hard coded port to make that coordination a little easier

gdubs18:07:51

Cool. Last night I started down the path of modifying the shadow hook to use open instead of start, that way it automatically opens a portal when I run shadow-cljs watch. Shouldn't be too hard to manage.

👍 2