Plutonomicon / cardano-transaction-lib

A Purescript library for building smart contract transactions on Cardano
https://plutonomicon.github.io/cardano-transaction-lib/
MIT License
93 stars 51 forks source link

Configure webpack proxies for all our services #1227

Open errfrom opened 2 years ago

errfrom commented 2 years ago

Seems odd to do it just for Kupo, is there any reason for this? We could do it for all, I got it working as a quick test with the following:

    proxy: {
      "/ogmios": {
        target: "http://localhost:1337",
        ws: true,
        changeOrigin: true,
        pathRewrite: { "^/ogmios": "" },
      },
      "/odc": {
        target: "http://localhost:9999",
        ws: true,
        changeOrigin: true,
        pathRewrite: { "^/odc": "" },
      },
      "/ctl": {
        target: "http://localhost:8081",
        changeOrigin: true,
        pathRewrite: { "^/ctl": "" },
      },

The biggest benefit of doing this is we can have a single domain + port for all services, which makes it easy to do remote testing via things like ngrok. We'd need a helper though to construct the server configs given the current domain + security, rather than fixed. I'd prefer to make this a separate issue though to get peoples opinions

_Originally posted by @jy14898 in https://github.com/Plutonomicon/cardano-transaction-lib/pull/1185#discussion_r1020960578_

klntsky commented 2 years ago

We'd need a helper though to construct the server configs given the current domain + security

What do you mean? Just helper functions to construct ServerConfigs?

klntsky commented 2 years ago

For ODC the path rewrite should be ws:


mkOgmiosDatumCacheWsUrl :: ServerConfig -> Url
mkOgmiosDatumCacheWsUrl cfg = mkWsUrl cfg <> "/ws"
jy14898 commented 2 years ago

We'd need a helper though to construct the server configs given the current domain + security

What do you mean? Just helper functions to construct ServerConfigs?

Yeah, we can't define them statically as it depends on whether you're accessing the page locally or on some full domain or IP address, or if we're in https, so it'd have to be in Effect/Aff.

For ODC the path rewrite should be ws:

The dev server redirects all paths, so ws is handled automatically. Eg localhost:4008/odc/ws -> localhost:9999/ws

I'm not sure if it is worth making these changes, however.

klntsky commented 2 years ago

Yeah, we can't define them statically as it depends on whether you're accessing the page locally or on some full domain or IP address, or if we're in https, so it'd have to be in Effect/Aff.

This should not be a part of our API. I don't see why is it needed at all, we only care about the dev environment in examples, which is always the same.

jy14898 commented 2 years ago

This should not be a part of our API. I don't see why is it needed at all, we only care about the dev environment in examples, which is always the same.

As a developer you may want to run the demos on your phone/on another PC/in a mobile wallet browser (Lode being one). To do so you'll have to access it by at least your LAN IP address, which means changing the configuration. Not the end of the world, but we could just have it work anywhere by making this change.

The helper is pretty trivial to make, I might say, so we could just have it as an Example util which isn't part of the library API.

jy14898 commented 1 year ago

It's actually quite annoying when trying to run contracts in node rather than browser, because we don't use webpack for node and therefore can't use the default kupo serverconfig