diff --git a/frontend/src/app.module.ts b/frontend/src/app.module.ts index fc8d2da..b78299c 100644 --- a/frontend/src/app.module.ts +++ b/frontend/src/app.module.ts @@ -18,7 +18,7 @@ import { HomeComponent } from './components/home.component' import { LoginComponent } from './components/login.component' import { InstanceInfoResolver } from './api' -// import '@fortawesome/fontawesome-svg-core/styles.css' +import '@fortawesome/fontawesome-svg-core/styles.css' const ROUTES = [ { diff --git a/frontend/src/components/home.component.ts b/frontend/src/components/home.component.ts index 432873d..4ea0ebb 100644 --- a/frontend/src/components/home.component.ts +++ b/frontend/src/components/home.component.ts @@ -15,9 +15,7 @@ class DemoConnector { private commonService: CommonService, private version: Version, ) { - this.getDistURL().then(distURL => { - targetWindow['tabbyWebDemoDataPath'] = `${distURL}/${version.version}/tabby-web-demo/data` - }) + targetWindow['tabbyWebDemoDataPath'] = `${this.getDistURL()}/${version.version}/tabby-web-demo/data` } async loadConfig (): Promise { @@ -36,8 +34,8 @@ class DemoConnector { return this.version.version } - async getDistURL (): Promise { - return await this.commonService.backendURL$ + '/app-dist' + getDistURL (): string { + return this.commonService.backendURL + '/app-dist' } getPluginsToLoad (): string[] { diff --git a/frontend/src/components/login.component.pug b/frontend/src/components/login.component.pug index 9e3e9b0..8ccce37 100644 --- a/frontend/src/components/login.component.pug +++ b/frontend/src/components/login.component.pug @@ -4,7 +4,7 @@ main(*ngIf='ready && loggedIn') a.btn( *ngFor='let provider of providers', [class]='provider.cls', - href='{{commonService.backendURL$|async}}/api/1/auth/social/login/{{provider.id}}' + href='{{commonService.backendURL}}/api/1/auth/social/login/{{provider.id}}' ) fa-icon([icon]='provider.icon', [fixedWidth]='true') span Log in with {{provider.name}} diff --git a/frontend/src/interceptor.ts b/frontend/src/interceptor.ts index 9fb9faa..04366d3 100644 --- a/frontend/src/interceptor.ts +++ b/frontend/src/interceptor.ts @@ -1,7 +1,6 @@ import { Injectable } from '@angular/core' import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http' -import { Observable, from } from 'rxjs' -import { switchMap } from 'rxjs/operators' +import { Observable } from 'rxjs' import { CommonService } from './services/common.service' @Injectable() @@ -9,16 +8,14 @@ export class UniversalInterceptor implements HttpInterceptor { constructor (private commonService: CommonService) { } intercept (request: HttpRequest, next: HttpHandler): Observable> { + console.log(request.url) if (!request.url.startsWith('//') && request.url.startsWith('/')) { - return from(this.commonService.backendURL$).pipe(switchMap((baseUrl: string) => { - const endpoint = request.url - - request = request.clone({ - url: `${baseUrl}${endpoint}`, - withCredentials: true, - }) - return next.handle(request) - })) + const endpoint = request.url + console.log(this.commonService.backendURL, request.url) + request = request.clone({ + url: `${this.commonService.backendURL}${endpoint}`, + withCredentials: true, + }) } return next.handle(request) } diff --git a/frontend/src/services/appConnector.service.ts b/frontend/src/services/appConnector.service.ts index 0707bd8..10f5918 100644 --- a/frontend/src/services/appConnector.service.ts +++ b/frontend/src/services/appConnector.service.ts @@ -159,8 +159,8 @@ export class AppConnectorService { return this.version.version } - async getDistURL (): Promise { - return await this.commonService.backendURL$ + '/app-dist' + getDistURL (): string { + return this.commonService.backendURL + '/app-dist' } getPluginsToLoad (): string[] { diff --git a/frontend/src/services/common.service.ts b/frontend/src/services/common.service.ts index ee10dda..a499ddd 100644 --- a/frontend/src/services/common.service.ts +++ b/frontend/src/services/common.service.ts @@ -1,23 +1,14 @@ import { Injectable } from '@angular/core' +declare const BACKEND_URL: any @Injectable({ providedIn: 'root' }) export class CommonService { - private configPromise: Promise - backendURL$: Promise + backendURL: string = BACKEND_URL constructor () { - this.configPromise = this.getConfig() - this.backendURL$ = this.configPromise.then(cfg => { - let backendURL = cfg.backendURL - if (backendURL.endsWith('/')) { - backendURL = backendURL.slice(0, -1) - } - return backendURL - }) - } - - private async getConfig () { - return (await fetch('/config.json')).json() + if (this.backendURL.endsWith('/')) { + this.backendURL = this.backendURL.slice(0, -1) + } } } diff --git a/frontend/src/terminal.ts b/frontend/src/terminal.ts index 91e4580..ab6f10d 100644 --- a/frontend/src/terminal.ts +++ b/frontend/src/terminal.ts @@ -31,7 +31,7 @@ async function start () { await (await fetch(url)).text() } - const baseUrl = `${await connector.getDistURL()}/${appVersion}` + const baseUrl = `${connector.getDistURL()}/${appVersion}` const coreURLs = [ `${baseUrl}/tabby-web-container/dist/preload.js`, `${baseUrl}/tabby-web-container/dist/bundle.js`, diff --git a/frontend/webpack.config.base.js b/frontend/webpack.config.base.js index 0a0ba44..c934be8 100644 --- a/frontend/webpack.config.base.js +++ b/frontend/webpack.config.base.js @@ -1,3 +1,4 @@ +require('dotenv').config({path: '../.env'}) const webpack = require('webpack') const MiniCssExtractPlugin = require("mini-css-extract-plugin") @@ -55,5 +56,8 @@ module.exports = { }, plugins: [ new MiniCssExtractPlugin(), + new webpack.DefinePlugin({ + BACKEND_URL: JSON.stringify(process.env.BACKEND_URL || ''), + }), ], } diff --git a/frontend/webpack.config.js b/frontend/webpack.config.js index c519107..09edd75 100644 --- a/frontend/webpack.config.js +++ b/frontend/webpack.config.js @@ -1,7 +1,6 @@ -require('dotenv').config() const baseConfig = require('./webpack.config.base.js') -const fs = require('fs') const path = require('path') +const webpack = require('webpack') const { AngularWebpackPlugin } = require('@ngtools/webpack') const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin const HtmlWebpackPlugin = require('html-webpack-plugin') @@ -12,15 +11,6 @@ const htmlPluginOptions = { } const outputPath = path.join(__dirname, 'build') -const backendURL = process.env.BACKEND_URL - -if (process.env.DEV && !backendURL) { - backendURL = 'http://localhost:8001' -} - -if (!backendURL) { - throw new Error('BACKEND_URL env var is required') -} module.exports = { name: 'browser', @@ -49,15 +39,6 @@ module.exports = { chunks: ['terminal'], ...htmlPluginOptions, }), - { - apply: (compiler) => { - compiler.hooks.afterEmit.tap('AfterEmitPlugin', () => { - fs.writeFileSync(path.join(outputPath, 'config.json'), JSON.stringify({ - backendURL, - })) - }) - }, - }, ], output: { path: outputPath,