Files
tabby-web/frontend/src/server.ts

66 lines
1.5 KiB
TypeScript
Raw Normal View History

2021-07-25 14:38:14 +02:00
import { install } from 'source-map-support'
2021-07-25 15:10:43 +02:00
import * as throng from 'throng'
2021-07-25 14:00:22 +02:00
2021-07-25 14:38:14 +02:00
import 'zone.js/dist/zone-node'
2021-07-25 14:00:22 +02:00
import './ssr-polyfills'
2021-07-24 20:25:09 +02:00
2021-07-25 14:38:14 +02:00
import { enableProdMode } from '@angular/core'
import { ngExpressEngine } from '@nguniversal/express-engine'
2021-07-24 20:25:09 +02:00
import * as express from 'express'
import { join } from 'path'
2021-07-25 15:10:43 +02:00
2021-07-25 14:38:14 +02:00
install()
enableProdMode()
2021-07-24 20:25:09 +02:00
import { AppServerModule } from './app.server.module'
2021-07-25 15:10:43 +02:00
const engine = ngExpressEngine({
2021-07-25 14:38:14 +02:00
bootstrap: AppServerModule,
2021-07-25 15:10:43 +02:00
})
2021-07-24 20:25:09 +02:00
2021-07-27 22:17:21 +02:00
const hardlinks = {
'cwd-detection': 'https://github.com/Eugeny/tabby/wiki/Shell-working-directory-reporting',
}
2021-07-25 15:10:43 +02:00
function start () {
const app = express()
2021-07-24 20:25:09 +02:00
2021-07-25 16:36:45 +02:00
const PORT = process.env.PORT || 8000
2021-07-25 15:10:43 +02:00
const DIST_FOLDER = join(process.cwd(), 'build')
2021-07-24 20:25:09 +02:00
2021-07-25 15:10:43 +02:00
app.engine('html', engine)
app.set('view engine', 'html')
app.set('views', DIST_FOLDER)
2021-07-26 18:34:18 +02:00
app.use('/static', express.static(DIST_FOLDER, {
2021-07-25 15:10:43 +02:00
maxAge: '1y',
}))
2021-07-26 18:34:18 +02:00
app.get(['/', '/app', '/login'], (req, res) => {
2021-07-25 15:10:43 +02:00
res.render('index', { req })
})
2021-07-26 21:00:13 +02:00
app.get(['/terminal'], (req, res) => {
res.sendFile(join(DIST_FOLDER, 'terminal.html'))
})
2021-07-27 22:17:21 +02:00
for (const [key, value] of Object.entries(hardlinks)) {
app.get(`/go/${key}`, (req, res) => res.redirect(value))
}
2021-07-25 17:15:13 +02:00
process.umask(0o002)
2021-07-25 15:10:43 +02:00
app.listen(PORT, () => {
console.log(`Node Express server listening on http://localhost:${PORT}`)
})
}
2021-07-24 20:25:09 +02:00
2021-07-25 15:10:43 +02:00
const WORKERS = process.env.WEB_CONCURRENCY || 4
throng({
workers: WORKERS,
lifetime: Infinity,
start,
2021-07-25 14:38:14 +02:00
})