]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server.ts
Blank instead of null for docker env
[github/Chocobozzz/PeerTube.git] / server.ts
index 97941c95822b26fd5377f598fe486ecafe8b966a..c0e679b02539195cc97bb3583e58af9b8dda5cf3 100644 (file)
--- a/server.ts
+++ b/server.ts
@@ -12,7 +12,6 @@ import * as bodyParser from 'body-parser'
 import * as express from 'express'
 import * as http from 'http'
 import * as morgan from 'morgan'
-import * as path from 'path'
 import * as bitTorrentTracker from 'bittorrent-tracker'
 import * as cors from 'cors'
 import { Server as WebSocketServer } from 'ws'
@@ -69,7 +68,15 @@ import { installApplication } from './server/initializers'
 import { Emailer } from './server/lib/emailer'
 import { JobQueue } from './server/lib/job-queue'
 import { VideosPreviewCache } from './server/lib/cache'
-import { apiRouter, clientsRouter, staticRouter, servicesRouter, webfingerRouter, activityPubRouter } from './server/controllers'
+import {
+  activityPubRouter,
+  apiRouter,
+  clientsRouter,
+  feedsRouter,
+  staticRouter,
+  servicesRouter,
+  webfingerRouter
+} from './server/controllers'
 import { Redis } from './server/lib/redis'
 import { BadActorFollowScheduler } from './server/lib/schedulers/bad-actor-follow-scheduler'
 import { RemoveOldJobsScheduler } from './server/lib/schedulers/remove-old-jobs-scheduler'
@@ -87,7 +94,7 @@ if (isTestInstance()) {
       req.path.indexOf(STATIC_PATHS.WEBSEED) === -1
     ) {
       return (cors({
-        origin: 'http://localhost:3000',
+        origin: '*',
         exposedHeaders: 'Retry-After',
         credentials: true
       }))(req, res, next)
@@ -144,23 +151,15 @@ app.use(apiRoute, apiRouter)
 // Services (oembed...)
 app.use('/services', servicesRouter)
 
-app.use('/', webfingerRouter)
 app.use('/', activityPubRouter)
-
-// Client files
-app.use('/', clientsRouter)
+app.use('/', feedsRouter)
+app.use('/', webfingerRouter)
 
 // Static files
 app.use('/', staticRouter)
 
-// Always serve index client page (the client is a single page application, let it handle routing)
-app.use('/*', function (req, res) {
-  if (req.accepts(ACCEPT_HEADERS) === 'html') {
-    return res.sendFile(path.join(__dirname, '../client/dist/index.html'))
-  }
-
-  return res.status(404).end()
-})
+// Client files, last valid routes!
+app.use('/', clientsRouter)
 
 // ----------- Errors -----------
 
@@ -185,6 +184,7 @@ app.use(function (err, req, res, next) {
 
 async function startApplication () {
   const port = CONFIG.LISTEN.PORT
+  const hostname = CONFIG.LISTEN.HOSTNAME
 
   await installApplication()
 
@@ -205,7 +205,8 @@ async function startApplication () {
   Redis.Instance.init()
 
   // Make server listening
-  server.listen(port)
-  logger.info('Server listening on port %d', port)
-  logger.info('Web server: %s', CONFIG.WEBSERVER.URL)
+  server.listen(port, hostname, () => {
+    logger.info('Server listening on %s:%d', hostname, port)
+    logger.info('Web server: %s', CONFIG.WEBSERVER.URL)
+  })
 }