Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend serving #46

Merged
merged 2 commits into from
Sep 30, 2019
Merged

frontend serving #46

merged 2 commits into from
Sep 30, 2019

Conversation

hansl
Copy link
Contributor

@hansl hansl commented Sep 27, 2019

No description provided.

@hansl
Copy link
Contributor Author

hansl commented Sep 27, 2019

@paulyoung This probably will not require a CORS because you can do requests to the same server that's serving your javascript.

It will respect address and port from the config (which it did not
previously), and will proxy calls to /api/ to the port 8080 locally
which is always reserved by the client.

Also added tests for (some parts of) the config.

Also now waits and blocks the process. When the user Ctrl-C or kill
dfx it will kill the nodemanager and the http server.
@hansl hansl changed the title Hansl/frontend serving frontend serving Sep 27, 2019
@paulyoung
Copy link
Contributor

I need to bring my feature branch up to date with master before I can try this, so doing that first and then will see if it unblocks me regarding CORS.

@paulyoung
Copy link
Contributor

I tried merging this into my local branch and got this:

⠁ Starting up the client...
binding to: V4(127.0.0.1:8000)
client: "http://localhost:8080/api"
thread '<unnamed>' panicked at 'System is not running', /nix/store/drq62qf7c389j8j82d69zysm7ljffjyj-crates-io/actix-rt-0.2.5/src/system.rs:78:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
Starting /Users/paulyoung/.cache/dfinity/versions/0.2.0/client /Users/paulyoung/.cache/dfinity/versions/0.2.0/nodemanager /Users/paulyoung⠂ Pinging the DFINITY client...
thread 'main' panicked at 'Invalid client URL.: RelativeUrlWithoutBase', src/libcore/result.rs:999:5

@paulyoung
Copy link
Contributor

I was able to reproduce on this branch with the following steps:

  1. cd sdk && nix-build $using_cache

For me this ended with:

...
/nix/store/l8i4m852dwbm4cjgy0zsw6ba2vkz000z-dfinity-sdk-rust
/nix/store/z0snx52xwh9l1f1m8r38d1j613hrm2pi-dfinity-sdk-rust
  1. cd dfx/examples/hello and edit dfinity.json:
diff --git a/dfx/examples/hello/dfinity.json b/dfx/examples/hello/dfinity.json
index 43af7a8..4cbb895 100644
--- a/dfx/examples/hello/dfinity.json
+++ b/dfx/examples/hello/dfinity.json
@@ -1,7 +1,18 @@
 {
+  "dfx": "{dfx_version}",
   "canisters": {
     "hello": {
       "main": "app/canisters/hello/main.as"
     }
+  },
+  "defaults": {
+    "build": {
+      "output": "build/"
+    },
+    "start": {
+      "port": 8000,
+      "address": "127.0.0.1",
+      "serve_root": "app/"
+    }
   }
 }
  1. Try using the first nix store path:
$ /nix/store/l8i4m852dwbm4cjgy0zsw6ba2vkz000z-dfinity-sdk-rust/bin/dfx start
⠁ Starting up the client...
binding to: V4(127.0.0.1:8000)
client: "http://localhost:8080/api"
thread '<unnamed>' panicked at 'thread 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }<unnamed>', ' panicked at 'src/libcore/result.rsSystem is not running:999', :/nix/store/drq62qf7c389j8j82d69zysm7ljffjyj-crates-io/actix-rt-0.2.5/src/system.rs5:
78note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
⠂ Pinging the DFINITY client...
thread 'main' panicked at 'Invalid client URL.: RelativeUrlWithoutBase', src/libcore/result.rs:999:5
  1. Try using the second one:
$ /nix/store/z0snx52xwh9l1f1m8r38d1j613hrm2pi-dfinity-sdk-rust/bin/dfx start
⠁ Starting up the client...
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/libcore/result.rs:999:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
binding to: V4(127.0.0.1:8000)
client: "http://localhost:8080/api"
⠂ Pinging the DFINITY client...
thread 'main' panicked at 'Invalid client URL.: RelativeUrlWithoutBase', src/libcore/result.rs:999:5

@paulyoung
Copy link
Contributor

I missed "version": 1, in dfinity.json but get similar results after that:

$ /nix/store/l8i4m852dwbm4cjgy0zsw6ba2vkz000z-dfinity-sdk-rust/bin/dfx start
⠁ Starting up the client...
binding to: V4(127.0.0.1:8000)
client: "http://localhost:8080/api"
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/libcore/result.rs:999:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
⠂ Pinging the DFINITY client...
thread 'main' panicked at 'Invalid client URL.: RelativeUrlWithoutBase', src/libcore/result.rs:999:5
$ /nix/store/z0snx52xwh9l1f1m8r38d1j613hrm2pi-dfinity-sdk-rust/bin/dfx start
⠁ Starting up the client...
binding to: V4(127.0thread '.<unnamed>0' panicked at '.called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }1', :src/libcore/result.rs8000)
client: "http://localhost:8080/api"
:999:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
⠂ Pinging the DFINITY client...
thread 'main' panicked at 'Invalid client URL.: RelativeUrlWithoutBase', src/libcore/result.rs:999:5

@paulyoung
Copy link
Contributor

I fixed {dfx_version} too, but no joy:

$ cat examples/hello/dfinity.json
{
  "version": 1,
  "dfx": "0.2.0",
  "canisters": {
    "hello": {
      "main": "app/canisters/hello/main.as"
    }
  },
  "defaults": {
    "build": {
      "output": "build/"
    },
    "start": {
      "port": 8000,
      "address": "127.0.0.1",
      "serve_root": "app/"
    }
  }
}
$ /nix/store/l8i4m852dwbm4cjgy0zsw6ba2vkz000z-dfinity-sdk-rust/bin/dfx start
⠁ Starting up the client...
binding to: V4(127.0.0.1:8000)
client: "http://localhost:8080/api"
thread '<unnamed>' panicked at 'System is not running', /nix/store/drq62qf7c389j8j82d69zysm7ljffjyj-crates-io/actix-rt-0.2.5/src/system.rs:78:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
⠂ Pinging the DFINITY client...
thread 'main' panicked at 'Invalid client URL.: RelativeUrlWithoutBase', src/libcore/result.rs:999:5

@paulyoung
Copy link
Contributor

I added http:// to the address, making it "address": "http://127.0.0.1", and got a bit further it seems:

$ /nix/store/l8i4m852dwbm4cjgy0zsw6ba2vkz000z-dfinity-sdk-rust/bin/dfx start
⠁ Starting up the client...
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:347:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@paulyoung
Copy link
Contributor

I also tried using the --host flag:

$ RUST_BACKTRACE=1 /nix/store/z0snx52xwh9l1f1m8r38d1j613hrm2pi-dfinity-sdk-rust/bin/dfx start --host http://127.0.0.1:8000
⠁ Starting up the client...
An error occured:
AddrParseError(
    AddrParseError(
        (),
    ),
)

@hansl hansl requested a review from a team as a code owner September 27, 2019 23:54
@hansl
Copy link
Contributor Author

hansl commented Sep 30, 2019

@paulyoung This should be fixed.

@paulyoung
Copy link
Contributor

Still seeing this:

$ dfx start
⠁ Starting up the client...
binding to: V4(127.0.0.1:8000)
client: "http://localhost:8080/api"
thread '<unnamed>' panicked at 'System is not running', /nix/store/drq62qf7c389j8j82d69zysm7ljffjyj-crates-io/actix-rt-0.2.5/src/system.rs:78:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
Starting /Users/paulyoung/.cache/dfinity/versions/0.2.0/client /Users/paulyoung/.cache/dfinity/versions/0.2.0/nodemanager /Users/paulyoung/.cache/dfinity/vers⠂ Pinging the DFINITY client...
thread 'main' panicked at 'Invalid client URL.: RelativeUrlWithoutBase', src/libcore/result.rs:999:5

@paulyoung
Copy link
Contributor

That was with:

$ dfx new foo
$ cd foo
$ dfx start

@paulyoung
Copy link
Contributor

Never mind, I don't have the latest changes. I did git merge origin/hansl/frontend-serving but forgot to fetch first.

Trying again.

@paulyoung
Copy link
Contributor

I'm still running into CORS issues:

Screen Shot 2019-09-30 at 11 27 44 AM

After the above I tried setting mode: "same-origin" and got: Fetch API cannot load http://localhost:8080/api/v1/submit. Request mode is "same-origin" but the URL's origin is not same as the request origin http://localhost:8000.

The port is part of the origin.

@hansl
Copy link
Contributor Author

hansl commented Sep 30, 2019 via email

@hansl hansl merged commit c73a1b6 into master Sep 30, 2019
@hansl hansl deleted the hansl/frontend-serving branch September 30, 2019 20:12
hansl added a commit that referenced this pull request Nov 9, 2020
commit 7c5e71488df430b89de637a15b56814db196e752
Author: Islam El-Ashi <ielashi@users.noreply.github.com>
Date:   Sat Nov 7 00:30:05 2020 +0100

    feat: DER-encode public key and principal ID when using Plain Authentication. (#48)

    BREAKING CHANGE

    If a developer relies on the inner work of SenderPubKey or manually instanciate Principal, the API changed.

commit a254861ae4bfe608734c8c190e4033cfe39f047b
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Fri Nov 6 15:17:32 2020 -0800

    chore(deps): bump node-fetch from 2.6.0 to 2.6.1 in /e2e/node (#49)

    Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1.
    - [Release notes](https://github.com/bitinn/node-fetch/releases)
    - [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md)
    - [Commits](node-fetch/node-fetch@v2.6.0...v2.6.1)

    Signed-off-by: dependabot[bot] <support@github.com>

    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 694849109bc28fea80119388504127e889b36d15
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Fri Nov 6 15:17:14 2020 -0800

    chore(deps-dev): bump node-fetch from 2.6.0 to 2.6.1 in /packages/agent (#50)

    Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1.
    - [Release notes](https://github.com/bitinn/node-fetch/releases)
    - [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md)
    - [Commits](node-fetch/node-fetch@v2.6.0...v2.6.1)

    Signed-off-by: dependabot[bot] <support@github.com>

    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 88af47f79b5e9f3a5e08abbf0ce03b3140357fc0
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Fri Nov 6 15:16:53 2020 -0800

    chore(deps-dev): bump node-fetch in /packages/bootstrap (#51)

    Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1.
    - [Release notes](https://github.com/bitinn/node-fetch/releases)
    - [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md)
    - [Commits](node-fetch/node-fetch@v2.6.0...v2.6.1)

    Signed-off-by: dependabot[bot] <support@github.com>

    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit ba4b082e5795150176f7adad989c3613edceb85f
Author: Hans <hans@larsen.online>
Date:   Thu Nov 5 12:49:59 2020 -0800

    test: add ic-ref, ci e2e and lerna support to repo (#47)

    This refactors the repository to use lerna to manage its monorepo's packages. It also adds the e2e tests from the SDK repo that we previously had to remove. More e2e tests will be added later, but this unblocks working with DER and Identity work as we can now at least run some e2e tests now (instead of mocking the http connection).

commit 8baa1cfc227d003c2806df1057b92009159df250
Author: Hans <hans@larsen.online>
Date:   Tue Nov 3 11:04:36 2020 -0800

    feat: use anonymous principal by default in HttpAgent (#46)

    If the auth transform is missing and the principal is anonymous, use an
    anonymous auth transform. Otherwise, use the auth transform as normal.

    # BREAKING CHANGE
    Before, an auth transform would not be called if it was missing, now it
    results as an error if the principal is not anonymous. This was because
    just using the packet as is without putting it in an envelope was a bug
    and should never be sent to a replica anyway. Now this is explicit.

commit 1a714e6c53f5e467112b964b71204b6d2eb545ef
Author: Hans <hans@larsen.online>
Date:   Tue Nov 3 11:04:15 2020 -0800

    feat: add a getPrincipal() method to Agents (#40)

commit 324e856944adb7f79a2afa2cffbdb6d144b35ab4
Author: Hans <hans@larsen.online>
Date:   Tue Nov 3 08:49:44 2020 -0800

    feat: add the canister ID to the window.ic object (#41)

    This can be useful to know the canister ID of the current frontend.

commit 8680a2cf4994b45c6e00ffb0b5a12b379f5ff919
Author: Hans <hans@larsen.online>
Date:   Mon Nov 2 21:57:21 2020 -0800

    feat: add a cache bust hash at the end of javascript output (#39)

commit 9f2ed968b7cc9f4b854af5e23edca19d34124909
Author: Benjamin Goering <benjamin.goering@dfinity.org>
Date:   Tue Sep 22 15:28:49 2020 -0700

    docs: polish docs/npm-publish.md per @hansl feedback (#37)

    via: pr feedback on dfinity/agent-js#36
mergify bot pushed a commit that referenced this pull request Nov 10, 2020
commit 19c28008db5fa1582da573088b17d0bdee9e8bc2
Author: Hans <hans@larsen.online>
Date:   Mon Nov 9 14:47:25 2020 -0800

    revert: Remove lerna (PR #47) (#59)
    
    This removes lerna, but attempt to not remove the e2e tests and the
    new packages/files that were added after the last PR.

commit 426a94f356bc4e27f50c8bec55071b82105adbd1
Author: Hans <hans@larsen.online>
Date:   Mon Nov 9 13:54:04 2020 -0800

    feat: use anonymous for the first retrieve (#53)
    
    Also include some cleanup of the scripts that arent used, and add a diagram for the
    bootstrapping process.
    
    This does not affect the worker yet. Only the first retrieve of the index.js on
    localhost.
    
    BREAKING CHANGE
    
    If a canister has a retrieve() method that relies on Principal, the principal used
    will change.
    
    Co-authored-by: Benjamin Goering <benjamin.goering@dfinity.org>

commit b795d8b34ce38dd35e1bcf2b80e33108cf74161d
Author: Andrew Wylde <2126677+codelemur@users.noreply.github.com>
Date:   Mon Nov 9 09:41:13 2020 -0800

    feat(idp): add identity-provider package to repository (#52)
    
    adds plain HTML/ts and test setup for project

commit 7c5e71488df430b89de637a15b56814db196e752
Author: Islam El-Ashi <ielashi@users.noreply.github.com>
Date:   Sat Nov 7 00:30:05 2020 +0100

    feat: DER-encode public key and principal ID when using Plain Authentication. (#48)
    
    BREAKING CHANGE
    
    If a developer relies on the inner work of SenderPubKey or manually instanciate Principal, the API changed.

commit a254861ae4bfe608734c8c190e4033cfe39f047b
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Fri Nov 6 15:17:32 2020 -0800

    chore(deps): bump node-fetch from 2.6.0 to 2.6.1 in /e2e/node (#49)
    
    Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1.
    - [Release notes](https://github.com/bitinn/node-fetch/releases)
    - [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md)
    - [Commits](node-fetch/node-fetch@v2.6.0...v2.6.1)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 694849109bc28fea80119388504127e889b36d15
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Fri Nov 6 15:17:14 2020 -0800

    chore(deps-dev): bump node-fetch from 2.6.0 to 2.6.1 in /packages/agent (#50)
    
    Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1.
    - [Release notes](https://github.com/bitinn/node-fetch/releases)
    - [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md)
    - [Commits](node-fetch/node-fetch@v2.6.0...v2.6.1)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 88af47f79b5e9f3a5e08abbf0ce03b3140357fc0
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Fri Nov 6 15:16:53 2020 -0800

    chore(deps-dev): bump node-fetch in /packages/bootstrap (#51)
    
    Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1.
    - [Release notes](https://github.com/bitinn/node-fetch/releases)
    - [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md)
    - [Commits](node-fetch/node-fetch@v2.6.0...v2.6.1)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit ba4b082e5795150176f7adad989c3613edceb85f
Author: Hans <hans@larsen.online>
Date:   Thu Nov 5 12:49:59 2020 -0800

    test: add ic-ref, ci e2e and lerna support to repo (#47)
    
    This refactors the repository to use lerna to manage its monorepo's packages. It also adds the e2e tests from the SDK repo that we previously had to remove. More e2e tests will be added later, but this unblocks working with DER and Identity work as we can now at least run some e2e tests now (instead of mocking the http connection).

commit 8baa1cfc227d003c2806df1057b92009159df250
Author: Hans <hans@larsen.online>
Date:   Tue Nov 3 11:04:36 2020 -0800

    feat: use anonymous principal by default in HttpAgent (#46)
    
    If the auth transform is missing and the principal is anonymous, use an
    anonymous auth transform. Otherwise, use the auth transform as normal.
    
    # BREAKING CHANGE
    Before, an auth transform would not be called if it was missing, now it
    results as an error if the principal is not anonymous. This was because
    just using the packet as is without putting it in an envelope was a bug
    and should never be sent to a replica anyway. Now this is explicit.

commit 1a714e6c53f5e467112b964b71204b6d2eb545ef
Author: Hans <hans@larsen.online>
Date:   Tue Nov 3 11:04:15 2020 -0800

    feat: add a getPrincipal() method to Agents (#40)

commit 324e856944adb7f79a2afa2cffbdb6d144b35ab4
Author: Hans <hans@larsen.online>
Date:   Tue Nov 3 08:49:44 2020 -0800

    feat: add the canister ID to the window.ic object (#41)
    
    This can be useful to know the canister ID of the current frontend.

commit 8680a2cf4994b45c6e00ffb0b5a12b379f5ff919
Author: Hans <hans@larsen.online>
Date:   Mon Nov 2 21:57:21 2020 -0800

    feat: add a cache bust hash at the end of javascript output (#39)

commit 9f2ed968b7cc9f4b854af5e23edca19d34124909
Author: Benjamin Goering <benjamin.goering@dfinity.org>
Date:   Tue Sep 22 15:28:49 2020 -0700

    docs: polish docs/npm-publish.md per @hansl feedback (#37)
    
    via: pr feedback on dfinity/agent-js#36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants