This repository has been archived on 2022-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
teemant-old/src/server/index.js

36 lines
1.1 KiB
JavaScript

'use strict'
import express from 'express'
import path from 'path'
import config from '../globals'
import logger from './logger'
const app = express()
const router = express.Router()
const pubdir = path.join(__dirname, 'public')
const port = config.server.port || 8080
const cacheAge = 365 * 24 * 60 * 60 * 1000
process.stdin.resume()
router.get('/', function (req, res) {
res.sendFile(path.join(pubdir, '/index.html'))
})
router.get('/:server?*', function (req, res) {
res.sendFile(path.join(pubdir, '/index.html'))
})
app.use('/', express.static(pubdir, { maxAge: cacheAge }))
app.use('/', express.static(path.join(pubdir, 'icons'), { maxAge: cacheAge }))
app.use('/', express.static(path.join(pubdir, 'static'), { maxAge: cacheAge }))
app.use('/:server', express.static(pubdir, { maxAge: cacheAge }))
app.use('/:server', express.static(path.join(pubdir, 'icons'), { maxAge: cacheAge }))
app.use('/:server', express.static(path.join(pubdir, 'static'), { maxAge: cacheAge }))
app.use('/', router)
app.listen(port, function () {
logger.log(`*** Listening on http://localhost:${port}/`)
})