Skip to content

Commit

Permalink
Now that vars are working, try using import.meta.env again
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsoniv committed Dec 18, 2023
1 parent adee692 commit e79781e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/App.router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import App from "./App";
import Profile from "./features/domains/ordercloud/components/Profile";
import Orders from "./features/domains/ordercloud/components/Orders";

const basename = process.env.VITE_APP_CONFIG_BASE;
const basename = import.meta.env.VITE_APP_CONFIG_BASE;

const router = createBrowserRouter([
{
Expand Down
15 changes: 6 additions & 9 deletions src/features/domains/ordercloud/constants.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
import { ApiRole } from "ordercloud-javascript-sdk";

//Basic auth configuration
const CONFIG_BASE = process.env.VITE_APP_CONFIG_BASE;
const BASE_API_URL = process.env.VITE_APP_ORDERCLOUD_BASE_API_URL || "https://api.ordercloud.io/v1";
const CLIENT_ID = process.env.VITE_APP_ORDERCLOUD_CLIENT_ID || "";
const SCOPE_STRING = process.env.VITE_APP_ORDERCLOUD_SCOPE || "";
const CUSTOM_SCOPE_STRING = process.env.VITE_APP_ORDERCLOUD_CUSTOM_SCOPE;
const CONFIG_BASE = import.meta.env.VITE_APP_CONFIG_BASE;
const BASE_API_URL = import.meta.env.VITE_APP_ORDERCLOUD_BASE_API_URL || "https://api.ordercloud.io/v1";
const CLIENT_ID = import.meta.env.VITE_APP_ORDERCLOUD_CLIENT_ID || "";
const SCOPE_STRING = import.meta.env.VITE_APP_ORDERCLOUD_SCOPE || "";
const CUSTOM_SCOPE_STRING = import.meta.env.VITE_APP_ORDERCLOUD_CUSTOM_SCOPE;

const SCOPE:ApiRole[] = SCOPE_STRING.split(',') as ApiRole[];
const CUSTOM_SCOPE:string[] = CUSTOM_SCOPE_STRING?.split(',') || [];

//Anonymous auth configuration
const ALLOW_ANONYMOUS_STRING = process.env.VITE_APP_ORDERCLOUD_ALLOW_ANONYMOUS;
const ALLOW_ANONYMOUS = ALLOW_ANONYMOUS_STRING ? ALLOW_ANONYMOUS_STRING === "true" : false;
const ALLOW_ANONYMOUS = JSON.parse(import.meta.env.VITE_APP_ORDERCLOUD_ALLOW_ANONYMOUS || "false");

console.log('consts', {
CONFIG_BASE,
BASE_API_URL,
CLIENT_ID,
SCOPE,
CUSTOM_SCOPE,
ALLOW_ANONYMOUS_STRING,
'type': typeof ALLOW_ANONYMOUS_STRING,
ALLOW_ANONYMOUS,
}, )

Expand Down
44 changes: 22 additions & 22 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ import react from "@vitejs/plugin-react";

export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
console.log("ENV", env);
const definitions = {
"process.env.VITE_APP_CONFIG_BASE": JSON.stringify(
env.VITE_APP_CONFIG_BASE
),
"process.env.VITE_APP_ORDERCLOUD_BASE_API_URL": JSON.stringify(
env.VITE_APP_ORDERCLOUD_BASE_API_URL
),
"process.env.VITE_APP_ORDERCLOUD_CLIENT_ID": JSON.stringify(
env.VITE_APP_ORDERCLOUD_CLIENT_ID
),
"process.env.VITE_APP_ORDERCLOUD_SCOPE": JSON.stringify(
env.VITE_APP_ORDERCLOUD_SCOPE
),
"process.env.VITE_APP_ORDERCLOUD_CUSTOM_SCOPE": JSON.stringify(
env.VITE_APP_ORDERCLOUD_CUSTOM_SCOPE
),
"process.env.VITE_APP_ORDERCLOUD_ALLOW_ANONYMOUS": JSON.stringify(
env.VITE_APP_ORDERCLOUD_ALLOW_ANONYMOUS
),
};
// console.log("ENV", env);
// const definitions = {
// "process.env.VITE_APP_CONFIG_BASE": JSON.stringify(
// env.VITE_APP_CONFIG_BASE
// ),
// "process.env.VITE_APP_ORDERCLOUD_BASE_API_URL": JSON.stringify(
// env.VITE_APP_ORDERCLOUD_BASE_API_URL
// ),
// "process.env.VITE_APP_ORDERCLOUD_CLIENT_ID": JSON.stringify(
// env.VITE_APP_ORDERCLOUD_CLIENT_ID
// ),
// "process.env.VITE_APP_ORDERCLOUD_SCOPE": JSON.stringify(
// env.VITE_APP_ORDERCLOUD_SCOPE
// ),
// "process.env.VITE_APP_ORDERCLOUD_CUSTOM_SCOPE": JSON.stringify(
// env.VITE_APP_ORDERCLOUD_CUSTOM_SCOPE
// ),
// "process.env.VITE_APP_ORDERCLOUD_ALLOW_ANONYMOUS": JSON.parse(
// env.VITE_APP_ORDERCLOUD_ALLOW_ANONYMOUS || "false"
// ),
// };
return {
base: env.VITE_APP_CONFIG_BASE,
plugins: [react()],
define: definitions,
// define: definitions,
};
});

0 comments on commit e79781e

Please sign in to comment.