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

54 lines
1.1 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-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 17:56:35 +02:00
app.get('*.*', express.static(join(DIST_FOLDER, 'static'), {
2021-07-25 15:10:43 +02:00
maxAge: '1y',
}))
app.get('*', (req, res) => {
res.render('index', { req })
})
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
})