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

Read canister ID from canister #528

Merged
merged 15 commits into from
Feb 4, 2022
Prev Previous commit
Next Next commit
Clean up webpack
  • Loading branch information
nmattia committed Feb 3, 2022
commit 65b908f138fae8ccf51a718d037790514663b414
23 changes: 11 additions & 12 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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
Expand All @@ -60,22 +63,19 @@ function generateWebpackConfigForCanister(name, info) {
queryParamsString += `${params}&`;
}

queryParamsString += `canisterId=${localCanister}`;
queryParamsString += `canisterId=${canisterId}`;

return path + queryParamsString;
},

}));
},
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
Expand Down Expand Up @@ -107,7 +107,6 @@ function generateWebpackConfigForCanister(name, info) {
process: require.resolve("process/browser"),
}),
new webpack.EnvironmentPlugin({
"CANISTER_ID": localCanister,
"II_ENV": "production"
}),
new CompressionPlugin({
Expand Down