This commit is contained in:
Eugene Pankov
2021-08-25 01:25:49 +02:00
parent f0497a081a
commit e541269392
12 changed files with 123 additions and 14 deletions

View File

@@ -21,6 +21,8 @@
<meta property="twitter:title" content="Tabby - a terminal for a more modern age">
<meta property="twitter:description" content="Tabby is a free and open source SSH, local and Telnet terminal with everything you'll ever need.">
<meta property="twitter:image" content="https://user-images.githubusercontent.com/161476/126016449-a053012a-e322-48ed-a2ab-3ed4f3281465.png">
<meta property="x-tabby-web-backend-url" content="{{backendURL}}">
</head>
<body>
<app></app>

View File

@@ -8,6 +8,7 @@ import { enableProdMode } from '@angular/core'
import { ngExpressEngine } from '@nguniversal/express-engine'
import * as express from 'express'
import { join } from 'path'
@@ -42,7 +43,19 @@ function start () {
}))
app.get(['/', '/app', '/login'], (req, res) => {
res.render('index', { req })
res.render(
'index',
{
req,
providers: [
{ provide: 'BACKEND_URL', useValue: process.env.BACKEND_URL ?? '' },
],
},
(err: Error, html: string) => {
html = html.replace('{{backendURL}}', process.env.BACKEND_URL ?? '')
res.status(err ? 500 : 200).send(html || err.message)
},
)
})
app.get(['/terminal'], (req, res) => {

View File

@@ -1,12 +1,23 @@
import { Injectable } from '@angular/core'
declare const BACKEND_URL: any
import { Inject, Injectable, Optional } from '@angular/core'
@Injectable({ providedIn: 'root' })
export class CommonService {
backendURL: string = BACKEND_URL
backendURL: string
constructor () {
constructor (@Inject('BACKEND_URL') @Optional() ssrBackendURL: string) {
const tag = (document.querySelector('meta[property=x-tabby-web-backend-url]') as HTMLMetaElement)
if (ssrBackendURL) {
this.backendURL = ssrBackendURL
tag.content = ssrBackendURL
} else {
if (tag.content && !tag.content.startsWith('{{')) {
this.backendURL = tag.content
} else {
this.backendURL = ''
}
}
console.log(this.backendURL)
if (this.backendURL.endsWith('/')) {
this.backendURL = this.backendURL.slice(0, -1)
}

View File

@@ -1,6 +1,8 @@
import './terminal-styles.scss'
async function start () {
window['__filename'] = ''
await new Promise<void>(resolve => {
window.addEventListener('message', event => {
if (event.data === 'connector-ready') {