]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server.ts
Fix "Off" player string localization
[github/Chocobozzz/PeerTube.git] / server.ts
index e46300dcef4be56974a82d84ba58bee6d27af6a9..9af83cde9ffa9973a447efcd5885d48c3fbbd009 100644 (file)
--- a/server.ts
+++ b/server.ts
@@ -7,13 +7,13 @@ if (isTestInstance()) {
 }
 
 // ----------- Node modules -----------
-import * as express from 'express'
-import * as morgan from 'morgan'
-import * as cors from 'cors'
-import * as cookieParser from 'cookie-parser'
-import * as helmet from 'helmet'
-import * as useragent from 'useragent'
-import * as anonymize from 'ip-anonymize'
+import express from 'express'
+import morgan, { token } from 'morgan'
+import cors from 'cors'
+import cookieParser from 'cookie-parser'
+import { frameguard } from 'helmet'
+import { parse } from 'useragent'
+import anonymize from 'ip-anonymize'
 import { program as cli } from 'commander'
 
 process.title = 'peertube'
@@ -61,7 +61,7 @@ if (CONFIG.CSP.ENABLED) {
 }
 
 if (CONFIG.SECURITY.FRAMEGUARD.ENABLED) {
-  app.use(helmet.frameguard({
+  app.use(frameguard({
     action: 'deny' // we only allow it for /videos/embed, see server/controllers/client.ts
   }))
 }
@@ -125,7 +125,7 @@ import { PeerTubeVersionCheckScheduler } from './server/lib/schedulers/peertube-
 import { Hooks } from './server/lib/plugins/hooks'
 import { PluginManager } from './server/lib/plugins/plugin-manager'
 import { LiveManager } from './server/lib/live'
-import { HttpStatusCode } from './shared/core-utils/miscs/http-error-codes'
+import { HttpStatusCode } from './shared/models/http/http-error-codes'
 import { VideosTorrentCache } from '@server/lib/files-cache/videos-torrent-cache'
 import { ServerConfigManager } from '@server/lib/server-config-manager'
 
@@ -148,16 +148,16 @@ if (isTestInstance()) {
 }
 
 // For the logger
-morgan.token('remote-addr', (req: express.Request) => {
+token('remote-addr', (req: express.Request) => {
   if (CONFIG.LOG.ANONYMIZE_IP === true || req.get('DNT') === '1') {
     return anonymize(req.ip, 16, 16)
   }
 
   return req.ip
 })
-morgan.token('user-agent', (req: express.Request) => {
+token('user-agent', (req: express.Request) => {
   if (req.get('DNT') === '1') {
-    return useragent.parse(req.get('user-agent')).family
+    return parse(req.get('user-agent')).family
   }
 
   return req.get('user-agent')
@@ -305,13 +305,19 @@ async function startApplication () {
   updateStreamingPlaylistsInfohashesIfNeeded()
     .catch(err => logger.error('Cannot update streaming playlist infohashes.', { err }))
 
-  if (cliOptions.plugins) await PluginManager.Instance.registerPluginsAndThemes()
-
   LiveManager.Instance.init()
   if (CONFIG.LIVE.ENABLED) LiveManager.Instance.run()
 
   // Make server listening
-  server.listen(port, hostname, () => {
+  server.listen(port, hostname, async () => {
+    if (cliOptions.plugins) {
+      try {
+        await PluginManager.Instance.registerPluginsAndThemes()
+      } catch (err) {
+        logger.error('Cannot register plugins and themes.', { err })
+      }
+    }
+
     logger.info('HTTP server listening on %s:%d', hostname, port)
     logger.info('Web server: %s', WEBSERVER.URL)