mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-23 16:23:00 +00:00
31 lines
811 B
TypeScript
31 lines
811 B
TypeScript
|
import { App, Plugin } from 'vue';
|
||
|
|
||
|
export class Advent22 {
|
||
|
private get api_baseurl(): string {
|
||
|
// in production mode, return "//host/api"
|
||
|
if (process.env.NODE_ENV === "production") {
|
||
|
return `//${window.location.host}/api`;
|
||
|
|
||
|
} else if (process.env.NODE_ENV !== "development") {
|
||
|
// not in prouction or development mode
|
||
|
console.warn("Unexpected NODE_ENV value");
|
||
|
}
|
||
|
|
||
|
// in development mode, return "//hostname:8000/api"
|
||
|
return `//${window.location.hostname}:8000/api`;
|
||
|
}
|
||
|
|
||
|
public api_url(endpoint?: string): string {
|
||
|
if (endpoint === undefined)
|
||
|
return `${this.api_baseurl}`;
|
||
|
|
||
|
return `${this.api_baseurl}/${endpoint}`;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export const Advent22Plugin: Plugin = {
|
||
|
install(app: App) {
|
||
|
app.config.globalProperties.$advent22 = new Advent22();
|
||
|
}
|
||
|
}
|