mirror of
https://github.com/Eugeny/tabby-web.git
synced 2026-08-17 06:46:05 +01:00
wip
This commit is contained in:
@@ -37,7 +37,7 @@ class DemoConnector {
|
||||
}
|
||||
|
||||
async getDistURL (): Promise<string> {
|
||||
return await this.commonService.getBackendURL() + '/app-dist'
|
||||
return await this.commonService.backendURL$ + '/app-dist'
|
||||
}
|
||||
|
||||
getPluginsToLoad (): string[] {
|
||||
|
||||
@@ -4,7 +4,7 @@ main(*ngIf='ready && loggedIn')
|
||||
a.btn(
|
||||
*ngFor='let provider of providers',
|
||||
[class]='provider.cls',
|
||||
href='/api/1/auth/social/login/{{provider.id}}'
|
||||
href='{{commonService.backendURL$|async}}/api/1/auth/social/login/{{provider.id}}'
|
||||
)
|
||||
fa-icon([icon]='provider.icon', [fixedWidth]='true')
|
||||
span Log in with {{provider.name}}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Component } from '@angular/core'
|
||||
import { LoginService } from '../services/login.service'
|
||||
import { CommonService } from '../services/common.service'
|
||||
|
||||
import { faGithub, faGitlab, faGoogle, faMicrosoft } from '@fortawesome/free-brands-svg-icons'
|
||||
|
||||
@@ -21,6 +22,7 @@ export class LoginComponent {
|
||||
|
||||
constructor (
|
||||
private loginService: LoginService,
|
||||
public commonService: CommonService,
|
||||
) { }
|
||||
|
||||
async ngOnInit () {
|
||||
|
||||
@@ -10,11 +10,12 @@ export class UniversalInterceptor implements HttpInterceptor {
|
||||
|
||||
intercept (request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||
if (!request.url.startsWith('//') && request.url.startsWith('/')) {
|
||||
return from(this.commonService.getBackendURL()).pipe(switchMap((baseUrl: string) => {
|
||||
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)
|
||||
}))
|
||||
|
||||
@@ -1,54 +1,39 @@
|
||||
require('source-map-support').install()
|
||||
import { install } from 'source-map-support'
|
||||
|
||||
import 'zone.js/dist/zone-node';
|
||||
import 'zone.js/dist/zone-node'
|
||||
import './ssr-polyfills'
|
||||
|
||||
import { enableProdMode } from '@angular/core';
|
||||
|
||||
// Express Engine
|
||||
import { ngExpressEngine } from '@nguniversal/express-engine';
|
||||
|
||||
import { enableProdMode } from '@angular/core'
|
||||
import { ngExpressEngine } from '@nguniversal/express-engine'
|
||||
|
||||
import * as express from 'express'
|
||||
import { join } from 'path'
|
||||
|
||||
// Faster server renders w/ Prod mode (dev mode never needed)
|
||||
enableProdMode();
|
||||
install()
|
||||
enableProdMode()
|
||||
|
||||
// Express server
|
||||
const app = express();
|
||||
const app = express()
|
||||
|
||||
const PORT = process.env.PORT || 4000;
|
||||
const DIST_FOLDER = join(process.cwd(), 'build');
|
||||
const PORT = process.env.PORT || 4000
|
||||
const DIST_FOLDER = join(process.cwd(), 'build')
|
||||
|
||||
import { AppServerModule } from './app.server.module'
|
||||
|
||||
app.engine('html', ngExpressEngine({
|
||||
bootstrap: AppServerModule,
|
||||
}));
|
||||
bootstrap: AppServerModule,
|
||||
}))
|
||||
|
||||
app.set('view engine', 'html');
|
||||
app.set('views', DIST_FOLDER);
|
||||
app.set('view engine', 'html')
|
||||
app.set('views', DIST_FOLDER)
|
||||
|
||||
// Example Express Rest API endpoints
|
||||
// app.get('/api/**', (req, res) => { });
|
||||
|
||||
// Server static files from /browser
|
||||
app.use('/static', express.static(DIST_FOLDER, {
|
||||
maxAge: '1y'
|
||||
}));
|
||||
|
||||
// var proxy = require('express-http-proxy');
|
||||
app.get('*.*', express.static(DIST_FOLDER, {
|
||||
maxAge: '1y',
|
||||
}))
|
||||
|
||||
app.get('*', (req, res) => {
|
||||
res.render('index', { req });
|
||||
});
|
||||
res.render('index', { req })
|
||||
})
|
||||
|
||||
|
||||
// app.use('/', proxy('http://tabby.local:8000/api/', {
|
||||
// }))
|
||||
|
||||
// Start up the Node server
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Node Express server listening on http://localhost:${PORT}`);
|
||||
});
|
||||
console.log(`Node Express server listening on http://localhost:${PORT}`)
|
||||
})
|
||||
|
||||
@@ -160,7 +160,7 @@ export class AppConnectorService {
|
||||
}
|
||||
|
||||
async getDistURL (): Promise<string> {
|
||||
return await this.commonService.getBackendURL() + '/app-dist'
|
||||
return await this.commonService.backendURL$ + '/app-dist'
|
||||
}
|
||||
|
||||
getPluginsToLoad (): string[] {
|
||||
|
||||
@@ -3,16 +3,21 @@ import { Injectable } from '@angular/core'
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CommonService {
|
||||
private backendURL?: string
|
||||
private configPromise: Promise<any>
|
||||
backendURL$: Promise<string>
|
||||
|
||||
async getBackendURL (): Promise<string> {
|
||||
if (!this.backendURL) {
|
||||
const config = await (await fetch('/config.json')).json()
|
||||
this.backendURL = config.backendURL
|
||||
if (this.backendURL.endsWith('/')) {
|
||||
this.backendURL = this.backendURL.slice(0, -1)
|
||||
constructor () {
|
||||
this.configPromise = this.getConfig()
|
||||
this.backendURL$ = this.configPromise.then(cfg => {
|
||||
let backendURL = cfg.backendURL
|
||||
if (backendURL.endsWith('/')) {
|
||||
backendURL = backendURL.slice(0, -1)
|
||||
}
|
||||
}
|
||||
return this.backendURL
|
||||
return backendURL
|
||||
})
|
||||
}
|
||||
|
||||
private async getConfig () {
|
||||
return (await fetch('/config.json')).json()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user