import { isTestInstance } from './server/helpers/core-utils'
if (isTestInstance()) {
require('source-map-support').install()
}
import * as bodyParser from 'body-parser'
import * as express from 'express'
import * as cors from 'cors'
import * as morgan from 'morgan'
import { apiRouter } from './server/controllers/api'
import { logger } from './server/helpers/logger'
import { API_VERSION, CONFIG, getWebserverUrl } from './server/initializers/constants'
import { VideosIndexer } from './server/lib/schedulers/videos-indexer'
import { initVideosIndex } from './server/lib/elastic-search-videos'
import { initChannelsIndex } from './server/lib/elastic-search-channels'
import { join } from 'path'
import { readFile } from 'fs-extra'
const app = express()
const url = getWebserverUrl()
app.use(morgan('combined', {
stream: { write: logger.info.bind(logger) }
}))
app.use(bodyParser.json({
type: [ 'application/json', 'application/*+json' ],
limit: '5mb'
}))
app.use(bodyParser.urlencoded({ extended: false }))
// ----------- Views, routes and static files -----------
app.use(cors())
const apiRoute = '/api/' + API_VERSION
app.use(apiRoute, apiRouter)
// Static client files
app.use('/js/', express.static(join(__dirname, '../client/dist/js')))
app.use('/css/', express.static(join(__dirname, '../client/dist/css')))
app.use('/img/', express.static(join(__dirname, '../client/dist/img')))
let indexHTML: string
app.use('/opensearch.xml', async function (req, res) {
return res.send(`