From bfd7ce977d9879077e92fabfc491240d8f230844 Mon Sep 17 00:00:00 2001 From: Bruno Caimar Date: Thu, 17 Oct 2024 10:17:26 -0300 Subject: [PATCH] fix: geocoder demo on windows #1140 (#1177) * fix: path to run properly on windows (#1140) * fix: readme instructions + redirect uri (https) --- demos/geocoder-browser/README.md | 6 +++--- demos/geocoder-browser/index.html | 2 +- scripts/get-package-json.js | 11 +++++++---- scripts/run-demo-server.js | 7 ++++--- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/demos/geocoder-browser/README.md b/demos/geocoder-browser/README.md index a63b815da8..3769a324b3 100644 --- a/demos/geocoder-browser/README.md +++ b/demos/geocoder-browser/README.md @@ -1,12 +1,12 @@ # Running this demo -1. Make sure you run `npm run bootstrap` in the root folder to setup the dependencies +1. Make sure you run `npm run build` in the root folder to setup the dependencies 2. Register a new app on https://developers.arcgis.com -3. Add a redirect URL of `http://localhost:8080/post-sign-in.html` to your app. +3. Add a redirect URL of `https://localhost:8080/authenticate.html` to your app. 4. Copy the `config.js.template` file, rename it to `config.js` 5. Copy your apps client id into your new `config.js` file. 6. `npm start` -7. Visit http://localhost:8080 and click "Sign In" to start the OAuth 2.0 process. +7. Visit https://localhost:8080 and click "Sign In" to start the OAuth 2.0 process. 8. Start clicking buttons to send off authenticated geocoding requests. **Note:** The server starts with a special configuration to serve URLs starting with `@esri/arcgis-rest-*` from their respective packages. In your application you will need to change these URLs to point to their respective locations. diff --git a/demos/geocoder-browser/index.html b/demos/geocoder-browser/index.html index 6d1763a615..9bfc58e6ba 100644 --- a/demos/geocoder-browser/index.html +++ b/demos/geocoder-browser/index.html @@ -55,7 +55,7 @@

get to geocodin!

authBtn.addEventListener('click', function (e) { arcgisRest.ArcGISIdentityManager.beginOAuth2({ clientId: ClientId, - redirectUri: "http://localhost:8080/authenticate.html", + redirectUri: "https://localhost:8080/authenticate.html", popup: true, portal: "https://www.arcgis.com/sharing/rest" }).then((session) => { diff --git a/scripts/get-package-json.js b/scripts/get-package-json.js index 466ba25b2e..d53d3f409d 100644 --- a/scripts/get-package-json.js +++ b/scripts/get-package-json.js @@ -1,9 +1,10 @@ import { readFile } from "fs/promises"; import { globby } from "globby"; import pkgDir from "pkg-dir"; -import { join, dirname } from "path"; +import { posix } from "path"; +import { fileURLToPath } from "url"; -const __dirname = dirname(new URL(import.meta.url).pathname); +const __dirname = fileURLToPath(new URL('.', import.meta.url)).replace(/\\/g, '/'); /** * Returns an object like: @@ -15,8 +16,10 @@ const __dirname = dirname(new URL(import.meta.url).pathname); * For all packages in the packages/* folder. */ export default async function getPackages() { - const rootDir = await pkgDir(__dirname); - const packageFiles = await globby(join(rootDir, "packages/*/package.json")); + const rootDir = (await pkgDir(__dirname)).replace(/\\/g, "/"); + + const packageFiles = await globby(posix.join(rootDir, "packages/*/package.json")); + return Promise.all( packageFiles.map((pkgPath) => { return readFile(pkgPath).then((pkg) => { diff --git a/scripts/run-demo-server.js b/scripts/run-demo-server.js index 45d94f50bb..92c315f4a7 100644 --- a/scripts/run-demo-server.js +++ b/scripts/run-demo-server.js @@ -1,15 +1,16 @@ import browserSync from "browser-sync"; -import { join, resolve, dirname } from "path"; +import { resolve, posix } from "path"; +import { fileURLToPath } from "url"; import getPackages from "./get-package-json.js"; (async () => { const cwd = process.cwd(); const packages = await getPackages(); - const __dirname = dirname(new URL(import.meta.url).pathname); + const __dirname = fileURLToPath(new URL('.', import.meta.url)).replace(/\\/g, '/'); const packageFolders = packages.map(({ name }) => { return { route: `/${name}`, - dir: resolve(join(__dirname, "../", "node_modules", name)) + dir: resolve(posix.join(__dirname, "../", "node_modules", name)) }; });