From 6f936be013b9b6c761563b3675dc034bd556388a Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Thu, 3 Feb 2022 13:50:46 +0100 Subject: [PATCH 01/15] webpack: redirect html to backend --- webpack.config.js | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 8340769f44..78fdb7aa02 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -3,6 +3,7 @@ const webpack = require("webpack"); const CopyPlugin = require("copy-webpack-plugin"); const TerserPlugin = require("terser-webpack-plugin"); const CompressionPlugin = require("compression-webpack-plugin"); +const HttpProxyMiddlware = require("http-proxy-middleware"); const dfxJson = require("./dfx.json"); require("dotenv").config(); @@ -43,13 +44,39 @@ function generateWebpackConfigForCanister(name, info) { path: path.join(__dirname, "dist"), }, devServer: { - port: 8080, - proxy: { - "/api": "http://localhost:8000", - "/authorize": "http://localhost:8081", + onBeforeSetupMiddleware: (devServer) => { + let replicaHost = "http://localhost:8000"; // TODO from file + + console.log("I am run"); + // basically everything _except_ for index.js, because we want live reload + devServer.app.get(['/', '/index.html', '/faq', '/faq', 'about' ], HttpProxyMiddlware.createProxyMiddleware( { + target: replicaHost, + pathRewrite: (pathAndParams, req) => { + let queryParamsString = `?`; + + const [path, params] = pathAndParams.split("?"); + + if (params) { + queryParamsString += `${params}&`; + } + + queryParamsString += `canisterId=${localCanister}`; + + return path + queryParamsString; + }, + + })); }, + port: 8080, + // TODO: why does /api redirect to the replica? + // TODO: why does /authorize redirect to 8081? + // + //proxy: { + //"/api": "http://localhost:8000", + //"/authorize": "http://localhost:8081", + //}, allowedHosts: [".localhost", ".local", ".ngrok.io"], - historyApiFallback: true, // makes sure our index is served on all endpoints, e.g. `/faq` + //historyApiFallback: true, // makes sure our index is served on all endpoints, e.g. `/faq` }, // Depending in the language or framework you are using for From 212d8f7d55d5d60ac24940a7d9a208389b38f24f Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Thu, 3 Feb 2022 15:07:13 +0100 Subject: [PATCH 02/15] Inject canister ID in assets --- Cargo.lock | 1 + src/frontend/assets/index.html | 11 +---- src/frontend/src/utils/iiConnection.ts | 3 +- src/internet_identity/Cargo.toml | 1 + src/internet_identity/src/assets.rs | 57 +++++++++++++++++++++++--- src/internet_identity/src/main.rs | 7 ++-- webpack.config.js | 9 ++-- 7 files changed, 65 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 624be28f7c..ef66013bef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -665,6 +665,7 @@ dependencies = [ "ic-cdk-macros", "ic-certified-map", "ic-types 0.1.5", + "lazy_static", "rand 0.8.4", "rand_chacha 0.2.2", "rand_core 0.5.1", diff --git a/src/frontend/assets/index.html b/src/frontend/assets/index.html index 19decbceb3..77450a14b2 100644 --- a/src/frontend/assets/index.html +++ b/src/frontend/assets/index.html @@ -11,6 +11,8 @@
+ + - diff --git a/src/frontend/src/utils/iiConnection.ts b/src/frontend/src/utils/iiConnection.ts index ad0fbe371e..189c53e67f 100644 --- a/src/frontend/src/utils/iiConnection.ts +++ b/src/frontend/src/utils/iiConnection.ts @@ -36,8 +36,9 @@ import { hasOwnProperty } from "./utils"; import * as tweetnacl from "tweetnacl"; import { fromMnemonicWithoutValidation } from "../crypto/ed25519"; +declare var canisterId: string; // TODO: error on undefined // eslint-disable-next-line -const canisterId: string = process.env.CANISTER_ID!; +//const canisterId: string = process.env.CANISTER_ID!; export const canisterIdPrincipal: Principal = Principal.fromText(canisterId); export const baseActor = Actor.createActor<_SERVICE>(internet_identity_idl, { agent: new HttpAgent({}), diff --git a/src/internet_identity/Cargo.toml b/src/internet_identity/Cargo.toml index d03ce3de65..dc2a79ff65 100644 --- a/src/internet_identity/Cargo.toml +++ b/src/internet_identity/Cargo.toml @@ -11,6 +11,7 @@ ic-cdk = "0.3.2" ic-cdk-macros = "0.3" ic-certified-map = "0.3.0" ic-types = "0.1.1" +lazy_static = "1.4.0" serde = "1" serde_bytes = "0.11" serde_cbor = "0.11" diff --git a/src/internet_identity/src/assets.rs b/src/internet_identity/src/assets.rs index 7a7d8fe7ff..9841c54da9 100644 --- a/src/internet_identity/src/assets.rs +++ b/src/internet_identity/src/assets.rs @@ -3,6 +3,9 @@ // This file describes which assets are used and how (content, content type and content encoding). use sha2::Digest; +use lazy_static::lazy_static; +use ic_cdk::api; + #[derive(Debug, PartialEq, Eq)] pub enum ContentEncoding { @@ -19,32 +22,74 @@ pub enum ContentType { SVG } -pub fn for_each_asset(mut f: impl FnMut(&'static str, ContentEncoding, ContentType, &'static [u8], &[u8; 32])) { +lazy_static! { + static ref INDEX_HTML_SETUP_JS: String = { + let canister_id = api::id(); + format!(r#"var canisterId = '{canister_id}';let s = document.createElement('script');s.async = false;s.src = 'index.js';document.head.appendChild(s);"#) + }; + + static ref INDEX_HTML_SETUP_JS_SRI_HASH: String = { + + let js: String = INDEX_HTML_SETUP_JS.to_string(); + let js: &[u8] = js.as_bytes(); + let hash: &[u8] = &sha2::Sha256::digest(js); + let hash = base64::encode(hash); + format!("sha256-{hash}") + //"sha256-9u6qNwkySNEgpTe1e3v0q2oIK9b+b3tB6nTAUew/VuQ=".to_string() + }; +} + +pub fn setup_hash() -> String { + INDEX_HTML_SETUP_JS_SRI_HASH.to_string() +} - let index_html = include_bytes!("../../../dist/index.html"); +lazy_static! { + + /* + Note: we cannot use a normal script tag like this + + because Firefox does not support SRI with CSP: https://bugzilla.mozilla.org/show_bug.cgi?id=1409200 + */ + static ref INDEX_HTML_STR: String = { + let index_html = include_str!("../../../dist/index.html"); + let foo: String = INDEX_HTML_SETUP_JS.to_string(); + let index_html = index_html.replace( + "", + &format!("").to_string() + ); + index_html + }; + + static ref INDEX_HTML: &'static [u8] = { + INDEX_HTML_STR.as_bytes() + }; +} + + +pub fn for_each_asset(mut f: impl FnMut(&'static str, ContentEncoding, ContentType, &'static [u8], &[u8; 32])) { let assets: [ (&str, &[u8], ContentEncoding, ContentType); 8] = [ ("/", - index_html, + &INDEX_HTML, ContentEncoding::Identity, ContentType::HTML, ), // The FAQ and about pages are the same webapp, but the webapp routes to the correct page ( "/faq", - index_html, + &INDEX_HTML, ContentEncoding::Identity, ContentType::HTML, ), ( "/about", - index_html, + &INDEX_HTML, ContentEncoding::Identity, ContentType::HTML, ), ( "/index.html", - index_html, + &INDEX_HTML, ContentEncoding::Identity, ContentType::HTML, ), diff --git a/src/internet_identity/src/main.rs b/src/internet_identity/src/main.rs index 60dc42c08b..ed85a36def 100644 --- a/src/internet_identity/src/main.rs +++ b/src/internet_identity/src/main.rs @@ -811,6 +811,7 @@ fn http_request(req: HttpRequest) -> HttpResponse { /// These headers enable browser security features (like limit access to platform apis and set /// iFrame policies, etc.). fn security_headers() -> Vec { + let hash = assets::setup_hash(); vec![ ("X-Frame-Options".to_string(), "DENY".to_string()), ("X-Content-Type-Options".to_string(), "nosniff".to_string()), @@ -834,17 +835,17 @@ fn security_headers() -> Vec { // infrastructure. ( "Content-Security-Policy".to_string(), - "default-src 'none';\ + format!("default-src 'none';\ connect-src 'self' https://ic0.app;\ img-src 'self' data:;\ - script-src 'sha256-syYd+YuWeLD80uCtKwbaGoGom63a0pZE5KqgtA7W1d8=' 'unsafe-inline' 'unsafe-eval' 'strict-dynamic' https:;\ + script-src '{hash}' 'unsafe-inline' 'unsafe-eval' 'strict-dynamic' https:;\ base-uri 'none';\ frame-ancestors 'none';\ form-action 'none';\ style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;\ style-src-elem 'unsafe-inline' https://fonts.googleapis.com;\ font-src https://fonts.gstatic.com;\ - upgrade-insecure-requests;" + upgrade-insecure-requests;") .to_string() ), ( diff --git a/webpack.config.js b/webpack.config.js index 78fdb7aa02..27d60f3495 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -68,13 +68,12 @@ function generateWebpackConfigForCanister(name, info) { })); }, port: 8080, - // TODO: why does /api redirect to the replica? // TODO: why does /authorize redirect to 8081? // - //proxy: { - //"/api": "http://localhost:8000", - //"/authorize": "http://localhost:8081", - //}, + proxy: { + "/api": "http://localhost:8000", + "/authorize": "http://localhost:8081", + }, allowedHosts: [".localhost", ".local", ".ngrok.io"], //historyApiFallback: true, // makes sure our index is served on all endpoints, e.g. `/faq` }, From 65b908f138fae8ccf51a718d037790514663b414 Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Thu, 3 Feb 2022 17:57:36 +0100 Subject: [PATCH 03/15] Clean up webpack --- webpack.config.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 27d60f3495..a7bede4595 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -7,12 +7,6 @@ const HttpProxyMiddlware = require("http-proxy-middleware"); const dfxJson = require("./dfx.json"); require("dotenv").config(); -let localCanister; - -try { - localCanister = require("./.dfx/local/canister_ids.json").internet_identity.local; -} catch {} - /** * Generate a webpack configuration for a canister. */ @@ -46,6 +40,15 @@ function generateWebpackConfigForCanister(name, info) { devServer: { onBeforeSetupMiddleware: (devServer) => { let replicaHost = "http://localhost:8000"; // TODO from file + const canisterIdsJson = './.dfx/local/canister_ids.json'; + + let canisterId; + + try { + canisterId = require(canisterIdsJson).internet_identity.local; + } catch (e) { + throw Error(`Could get canister ID from ${canisterIdsJson}: ${e}`); + } console.log("I am run"); // basically everything _except_ for index.js, because we want live reload @@ -60,7 +63,7 @@ function generateWebpackConfigForCanister(name, info) { queryParamsString += `${params}&`; } - queryParamsString += `canisterId=${localCanister}`; + queryParamsString += `canisterId=${canisterId}`; return path + queryParamsString; }, @@ -68,14 +71,11 @@ function generateWebpackConfigForCanister(name, info) { })); }, port: 8080, - // TODO: why does /authorize redirect to 8081? - // proxy: { + // Make sure /api calls land on the replica (and not on webpack) "/api": "http://localhost:8000", - "/authorize": "http://localhost:8081", }, allowedHosts: [".localhost", ".local", ".ngrok.io"], - //historyApiFallback: true, // makes sure our index is served on all endpoints, e.g. `/faq` }, // Depending in the language or framework you are using for @@ -107,7 +107,6 @@ function generateWebpackConfigForCanister(name, info) { process: require.resolve("process/browser"), }), new webpack.EnvironmentPlugin({ - "CANISTER_ID": localCanister, "II_ENV": "production" }), new CompressionPlugin({ From 6c3c62de8b6134d25dbe445db8e480eedf5bea96 Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Thu, 3 Feb 2022 17:57:48 +0100 Subject: [PATCH 04/15] Clean up iiConnection --- src/frontend/src/utils/iiConnection.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/frontend/src/utils/iiConnection.ts b/src/frontend/src/utils/iiConnection.ts index 189c53e67f..dfed7b368e 100644 --- a/src/frontend/src/utils/iiConnection.ts +++ b/src/frontend/src/utils/iiConnection.ts @@ -37,8 +37,6 @@ import * as tweetnacl from "tweetnacl"; import { fromMnemonicWithoutValidation } from "../crypto/ed25519"; declare var canisterId: string; // TODO: error on undefined -// eslint-disable-next-line -//const canisterId: string = process.env.CANISTER_ID!; export const canisterIdPrincipal: Principal = Principal.fromText(canisterId); export const baseActor = Actor.createActor<_SERVICE>(internet_identity_idl, { agent: new HttpAgent({}), From 0c26aca9847d8b381776fd6de167e2914384d24d Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Thu, 3 Feb 2022 18:09:44 +0100 Subject: [PATCH 05/15] Clean up assets --- src/internet_identity/src/assets.rs | 25 ++++++------------------- src/internet_identity/src/main.rs | 15 ++++++++++----- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/internet_identity/src/assets.rs b/src/internet_identity/src/assets.rs index 9841c54da9..547a027332 100644 --- a/src/internet_identity/src/assets.rs +++ b/src/internet_identity/src/assets.rs @@ -22,6 +22,9 @@ pub enum ContentType { SVG } +// Note about using lazy_static as memoization +// is this necessary? + lazy_static! { static ref INDEX_HTML_SETUP_JS: String = { let canister_id = api::id(); @@ -39,10 +42,6 @@ lazy_static! { }; } -pub fn setup_hash() -> String { - INDEX_HTML_SETUP_JS_SRI_HASH.to_string() -} - lazy_static! { /* @@ -65,10 +64,8 @@ lazy_static! { }; } - -pub fn for_each_asset(mut f: impl FnMut(&'static str, ContentEncoding, ContentType, &'static [u8], &[u8; 32])) { - - let assets: [ (&str, &[u8], ContentEncoding, ContentType); 8] = [ +pub fn get_assets() -> [ (&'static str, &'static [u8], ContentEncoding, ContentType); 8] { + [ ("/", &INDEX_HTML, ContentEncoding::Identity, @@ -117,16 +114,6 @@ pub fn for_each_asset(mut f: impl FnMut(&'static str, ContentEncoding, ContentTy ContentEncoding::Identity, ContentType::SVG, ), - ]; - - for (name, content, encoding, content_type) in assets { - let hash = hash_content(content); - f(name, encoding, content_type, content, &hash); - } -} - + ] -// Hash the content of an asset in an `ic_certified_map` friendly way -fn hash_content(bytes: &[u8]) -> [u8; 32] { - sha2::Sha256::digest(bytes).into() } diff --git a/src/internet_identity/src/main.rs b/src/internet_identity/src/main.rs index ed85a36def..a26c9f48bc 100644 --- a/src/internet_identity/src/main.rs +++ b/src/internet_identity/src/main.rs @@ -11,6 +11,7 @@ use internet_identity::signature_map::SignatureMap; use rand_chacha::rand_core::{RngCore, SeedableRng}; use serde::Serialize; use serde_bytes::{ByteBuf, Bytes}; +use sha2::Digest; use std::borrow::Cow; use std::cell::{Cell, RefCell}; use std::collections::HashMap; @@ -923,9 +924,12 @@ fn init_assets() { ASSETS.with(|a| { let mut assets = a.borrow_mut(); - assets::for_each_asset(|name, encoding, content_type, contents, hash| { - asset_hashes.insert(name, *hash); - let mut headers = match encoding { + for (path, content, content_encoding, content_type) in assets::get_assets() { + + let hash: [u8; 32] = sha2::Sha256::digest(content).into(); + asset_hashes.insert(path, hash); + + let mut headers = match content_encoding { ContentEncoding::Identity => vec![], ContentEncoding::GZip => { vec![("Content-Encoding".to_string(), "gzip".to_string())] @@ -935,8 +939,9 @@ fn init_assets() { "Content-Type".to_string(), content_type.to_mime_type_string(), )); - assets.insert(name, (headers, contents)); - }); + assets.insert(path, (headers, content)); + + } }); }); } From be81bfe1ffd27a5ae695eb462ecafb34e13d754d Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Thu, 3 Feb 2022 18:28:17 +0100 Subject: [PATCH 06/15] Clean up and document assets --- src/frontend/assets/index.html | 12 +++----- src/internet_identity/src/assets.rs | 44 +++++++++++------------------ src/internet_identity/src/main.rs | 7 ++++- 3 files changed, 26 insertions(+), 37 deletions(-) diff --git a/src/frontend/assets/index.html b/src/frontend/assets/index.html index 77450a14b2..13f805cae1 100644 --- a/src/frontend/assets/index.html +++ b/src/frontend/assets/index.html @@ -11,15 +11,11 @@
- + + + - diff --git a/src/internet_identity/src/assets.rs b/src/internet_identity/src/assets.rs index 547a027332..899934f8b2 100644 --- a/src/internet_identity/src/assets.rs +++ b/src/internet_identity/src/assets.rs @@ -6,7 +6,6 @@ use sha2::Digest; use lazy_static::lazy_static; use ic_cdk::api; - #[derive(Debug, PartialEq, Eq)] pub enum ContentEncoding { Identity, @@ -22,33 +21,23 @@ pub enum ContentType { SVG } -// Note about using lazy_static as memoization -// is this necessary? - lazy_static! { + // The - because Firefox does not support SRI with CSP: https://bugzilla.mozilla.org/show_bug.cgi?id=1409200 - */ + // The full content of the index.html, after the canister ID (and script tag) have been + // injected static ref INDEX_HTML_STR: String = { let index_html = include_str!("../../../dist/index.html"); let foo: String = INDEX_HTML_SETUP_JS.to_string(); @@ -58,35 +47,34 @@ lazy_static! { ); index_html }; - - static ref INDEX_HTML: &'static [u8] = { - INDEX_HTML_STR.as_bytes() - }; } +// Get all the assets. Duplicated assets like index.html are shared and generally all assets are +// prepared only once (like injecting the canister ID). pub fn get_assets() -> [ (&'static str, &'static [u8], ContentEncoding, ContentType); 8] { + let index_html: &[u8] = INDEX_HTML_STR.as_bytes(); [ ("/", - &INDEX_HTML, - ContentEncoding::Identity, - ContentType::HTML, + index_html, + ContentEncoding::Identity, + ContentType::HTML, ), // The FAQ and about pages are the same webapp, but the webapp routes to the correct page ( "/faq", - &INDEX_HTML, + index_html, ContentEncoding::Identity, ContentType::HTML, ), ( "/about", - &INDEX_HTML, + index_html, ContentEncoding::Identity, ContentType::HTML, ), ( "/index.html", - &INDEX_HTML, + index_html, ContentEncoding::Identity, ContentType::HTML, ), diff --git a/src/internet_identity/src/main.rs b/src/internet_identity/src/main.rs index a26c9f48bc..32fb312ef5 100644 --- a/src/internet_identity/src/main.rs +++ b/src/internet_identity/src/main.rs @@ -812,7 +812,7 @@ fn http_request(req: HttpRequest) -> HttpResponse { /// These headers enable browser security features (like limit access to platform apis and set /// iFrame policies, etc.). fn security_headers() -> Vec { - let hash = assets::setup_hash(); + let hash = assets::INDEX_HTML_SETUP_JS_SRI_HASH.to_string(); vec![ ("X-Frame-Options".to_string(), "DENY".to_string()), ("X-Content-Type-Options".to_string(), "nosniff".to_string()), @@ -834,6 +834,11 @@ fn security_headers() -> Vec { // style-src 'unsafe-inline' is currently required due to the way styles are handled by the // application. Adding hashes would require a big restructuring of the application and build // infrastructure. + // + // NOTE about `script-src`: we cannot use a normal script tag like this + // + // because Firefox does not support SRI with CSP: https://bugzilla.mozilla.org/show_bug.cgi?id=1409200 + // Instead, we add it to the CSP policy ( "Content-Security-Policy".to_string(), format!("default-src 'none';\ From 0257856b8477c483bf4645e624eab0b5e9789cb9 Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Thu, 3 Feb 2022 18:40:47 +0100 Subject: [PATCH 07/15] Show error if canister ID is not set --- src/frontend/src/utils/iiConnection.ts | 16 +++++++++++++++- src/internet_identity/src/assets.rs | 3 ++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/frontend/src/utils/iiConnection.ts b/src/frontend/src/utils/iiConnection.ts index dfed7b368e..f2d51860f3 100644 --- a/src/frontend/src/utils/iiConnection.ts +++ b/src/frontend/src/utils/iiConnection.ts @@ -34,9 +34,23 @@ import { Principal } from "@dfinity/principal"; import { MultiWebAuthnIdentity } from "./multiWebAuthnIdentity"; import { hasOwnProperty } from "./utils"; import * as tweetnacl from "tweetnacl"; +import { displayError } from "../components/displayError"; import { fromMnemonicWithoutValidation } from "../crypto/ed25519"; -declare var canisterId: string; // TODO: error on undefined +declare const canisterId: string; + +// Check if the canister ID was defined before we even try to read it +if(typeof canisterId !== undefined) { + displayError({ + title: "Canister ID not set", + message: + "There was a problem contacting the IC. The host serving this page did not give us a canister ID. Try reloading the page and contact support if the problem persists.", + primaryButton: "Reload", + }).then(() => { + window.location.reload(); + }); +} + export const canisterIdPrincipal: Principal = Principal.fromText(canisterId); export const baseActor = Actor.createActor<_SERVICE>(internet_identity_idl, { agent: new HttpAgent({}), diff --git a/src/internet_identity/src/assets.rs b/src/internet_identity/src/assets.rs index 899934f8b2..8b613c0372 100644 --- a/src/internet_identity/src/assets.rs +++ b/src/internet_identity/src/assets.rs @@ -25,7 +25,8 @@ lazy_static! { // The - + diff --git a/src/frontend/src/utils/iiConnection.ts b/src/frontend/src/utils/iiConnection.ts index f2d51860f3..8f39b69dba 100644 --- a/src/frontend/src/utils/iiConnection.ts +++ b/src/frontend/src/utils/iiConnection.ts @@ -40,15 +40,15 @@ import { fromMnemonicWithoutValidation } from "../crypto/ed25519"; declare const canisterId: string; // Check if the canister ID was defined before we even try to read it -if(typeof canisterId !== undefined) { - displayError({ - title: "Canister ID not set", - message: - "There was a problem contacting the IC. The host serving this page did not give us a canister ID. Try reloading the page and contact support if the problem persists.", - primaryButton: "Reload", - }).then(() => { - window.location.reload(); - }); +if (typeof canisterId !== undefined) { + displayError({ + title: "Canister ID not set", + message: + "There was a problem contacting the IC. The host serving this page did not give us a canister ID. Try reloading the page and contact support if the problem persists.", + primaryButton: "Reload", + }).then(() => { + window.location.reload(); + }); } export const canisterIdPrincipal: Principal = Principal.fromText(canisterId); From c69014cb164a3f1e0fca7dee518ed4d056de622a Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Thu, 3 Feb 2022 18:52:50 +0100 Subject: [PATCH 12/15] Update Dockerfile --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ef34a2ccba..2ab1618729 100644 --- a/Dockerfile +++ b/Dockerfile @@ -62,7 +62,6 @@ FROM deps as build COPY . . -ENV CANISTER_ID=rdmx6-jaaaa-aaaaa-aaadq-cai ARG II_ENV=production RUN npm ci From b0ec7b3ed26b89564cb733272857af453e99b7c8 Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Fri, 4 Feb 2022 10:19:50 +0100 Subject: [PATCH 13/15] s/foo/setup_js/ --- src/internet_identity/src/assets.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/internet_identity/src/assets.rs b/src/internet_identity/src/assets.rs index 899934f8b2..83a4cd49e3 100644 --- a/src/internet_identity/src/assets.rs +++ b/src/internet_identity/src/assets.rs @@ -40,10 +40,10 @@ lazy_static! { // injected static ref INDEX_HTML_STR: String = { let index_html = include_str!("../../../dist/index.html"); - let foo: String = INDEX_HTML_SETUP_JS.to_string(); + let setup_js: String = INDEX_HTML_SETUP_JS.to_string(); let index_html = index_html.replace( "", - &format!("").to_string() + &format!("").to_string() ); index_html }; From 851f0708a3ff661c4aa9436af9cfc41947a93c5c Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Fri, 4 Feb 2022 10:21:06 +0100 Subject: [PATCH 14/15] Add note about http:// --- webpack.config.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/webpack.config.js b/webpack.config.js index 9343849573..beb5ca23e6 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -51,6 +51,8 @@ function generateWebpackConfigForCanister(name, info) { throw Error(`Could get host from ${dfxJson}: ${e}`); } + // If the replicaHost lacks protocol (e.g. 'localhost:8000') the + // requests are not forwarded properly if(!replicaHost.startsWith("http://")) { replicaHost = `http://${replicaHost}`; } From b3f9eab68b94702dcd1de5c2fb7751825c3b855b Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Fri, 4 Feb 2022 10:22:48 +0100 Subject: [PATCH 15/15] Use double-quotes to please formatter --- src/internet_identity/src/assets.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/internet_identity/src/assets.rs b/src/internet_identity/src/assets.rs index 83a4cd49e3..657857baaf 100644 --- a/src/internet_identity/src/assets.rs +++ b/src/internet_identity/src/assets.rs @@ -42,8 +42,8 @@ lazy_static! { let index_html = include_str!("../../../dist/index.html"); let setup_js: String = INDEX_HTML_SETUP_JS.to_string(); let index_html = index_html.replace( - "", - &format!("").to_string() + r#""#, + &format!(r#""#).to_string() ); index_html };