Skip to content

Commit

Permalink
feat: allow deployment on a different base path, fixes #113
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriansaliou committed Jun 20, 2024
1 parent c9582f1 commit b700bd5
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 43 deletions.
6 changes: 5 additions & 1 deletion config/common.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"platform": "web"
"platform": "web",

"context": {
"basePath": "/"
}
}
9 changes: 8 additions & 1 deletion src/assemblies/inbox/InboxMessaging.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
)
iframe(
@load="onFrameLoad"
:src="frameUrl"
:class=`[
"a-inbox-messaging__frame",
{
"a-inbox-messaging__frame--visible": isFrameLoaded
}
]`
src="/includes/views/messaging.html"
ref="frame"
sandbox="allow-same-origin allow-scripts"
)
Expand Down Expand Up @@ -171,6 +171,9 @@ import MessageDetails from "@/popups/inbox/MessageDetails.vue";
// PROJECT: COMPOSABLES
import { useEvents } from "@/composables/events";

// PROJECT: COMMONS
import CONFIG from "@/commons/config";

// PROJECT: STORES
import Store from "@/store";
import { EventAvatarGeneric } from "@/store/tables/avatar";
Expand Down Expand Up @@ -408,6 +411,10 @@ export default {
return this.roomItem?.unreadCount || 0;
},

frameUrl(): string {
return `${CONFIG.context.basePath}includes/views/messaging.html`;
},

selfJID(): JID {
return this.account.getSelfJID();
},
Expand Down
5 changes: 4 additions & 1 deletion src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import AppSpotlightBrowseBlocked from "@/views/app/spotlight/AppSpotlightBrowseB
import AppInboxBase from "@/views/app/inbox/AppInboxBase.vue";
import StartLogin from "@/views/start/StartLogin.vue";

// PROJECT: COMMONS
import CONFIG from "@/commons/config";

// PROJECT: STORES
import Store from "@/store";

Expand Down Expand Up @@ -63,7 +66,7 @@ class Router {
constructor() {
// Create router
this.__router = createRouter({
history: createWebHistory(),
history: createWebHistory(CONFIG.context.basePath),

routes: [
// --> START <--
Expand Down
110 changes: 70 additions & 40 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ import commonConfig from "./config/common";
import developmentConfig from "./config/development";
import productionConfig from "./config/production";

/**************************************************************************
* INTERFACES
* ************************************************************************* */

interface Configuration {
environment: string;
platform: string;

context: {
basePath: string;
};

overrides?: {
hostMeta?: string;
};
}

/**************************************************************************
* CONSTANTS
* ************************************************************************* */
Expand Down Expand Up @@ -59,12 +76,63 @@ const INLINE_DATA_ITEMS = {
styles: BuilderInline.styles()
};

/**************************************************************************
* CONFIGURATION
* ************************************************************************* */

const CONFIG: Configuration = (function () {
// Initialize empty configuration
const config = {
environment: "",
platform: "",

context: {
basePath: ""
}
};

// Merge common configuration
merge(config, commonConfig);

// Merge per-environment configuration
switch (process.env.NODE_ENV) {
case "production": {
merge(config, productionConfig);

break;
}

default: {
merge(config, developmentConfig);
}
}

// Merge local configuration? (if any)
try {
const localConfig = JSON.parse(
fs.readFileSync("./config/local.json", "utf8")
);

merge(config, localConfig);
} catch (_) {
// Ignore errors (local configuration not found)
}

// Replace platform with custom platform? (if any)
// Notice: this only applies to Tauri builds (eg. macOS bundle)
if (PLATFORM_APPLICATION_OVERRIDE) {
merge(config, { platform: PLATFORM_APPLICATION_OVERRIDE });
}

return config;
})();

/**************************************************************************
* EXPORTS
* ************************************************************************* */

export default {
base: "/",
base: CONFIG.context.basePath,
publicDir: "public",
logLevel: "info",

Expand Down Expand Up @@ -179,44 +247,6 @@ export default {

define: {
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: false,

__CONFIG__: (function () {
const config = {};

// Merge common configuration
merge(config, commonConfig);

// Merge per-environment configuration
switch (process.env.NODE_ENV) {
case "production": {
merge(config, productionConfig);

break;
}

default: {
merge(config, developmentConfig);
}
}

// Merge local configuration? (if any)
try {
const localConfig = JSON.parse(
fs.readFileSync("./config/local.json", "utf8")
);

merge(config, localConfig);
} catch (_) {
// Ignore errors (local configuration not found)
}

// Replace platform with custom platform? (if any)
// Notice: this only applies to Tauri builds (eg. macOS bundle)
if (PLATFORM_APPLICATION_OVERRIDE) {
merge(config, { platform: PLATFORM_APPLICATION_OVERRIDE });
}

return config;
})()
__CONFIG__: CONFIG
}
};

0 comments on commit b700bd5

Please sign in to comment.