]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server.js
Remove Node 4 support
[github/Chocobozzz/PeerTube.git] / server.js
index 6eb0220004b3a2f5238c3ae0333282415752162a..33d399786da00edd0f787ee8cba3b7819ed09ba9 100644 (file)
--- a/server.js
+++ b/server.js
@@ -17,10 +17,10 @@ const app = express()
 
 // ----------- Database -----------
 const constants = require('./server/initializers/constants')
-const database = require('./server/initializers/database')
 const logger = require('./server/helpers/logger')
-
-database.connect()
+// Initialize database and models
+const db = require('./server/initializers/database')
+db.init(onDatabaseInitDone)
 
 // ----------- Checker -----------
 const checker = require('./server/initializers/checker')
@@ -37,11 +37,10 @@ if (errorMessage !== null) {
 
 // ----------- PeerTube modules -----------
 const customValidators = require('./server/helpers/custom-validators')
+const friends = require('./server/lib/friends')
 const installer = require('./server/initializers/installer')
 const migrator = require('./server/initializers/migrator')
-const mongoose = require('mongoose')
 const routes = require('./server/controllers')
-const Request = mongoose.model('Request')
 
 // ----------- Command line -----------
 
@@ -59,7 +58,8 @@ app.use(expressValidator({
     customValidators.misc,
     customValidators.pods,
     customValidators.users,
-    customValidators.videos
+    customValidators.videos,
+    customValidators.remote.videos
   )
 }))
 
@@ -119,25 +119,27 @@ app.use(function (err, req, res, next) {
 
 // ----------- Run -----------
 
-const port = constants.CONFIG.LISTEN.PORT
-installer.installApplication(function (err) {
-  if (err) throw err
-
-  // Run the migration scripts if needed
+function onDatabaseInitDone () {
+  const port = constants.CONFIG.LISTEN.PORT
+    // Run the migration scripts if needed
   migrator.migrate(function (err) {
     if (err) throw err
 
-    // ----------- Make the server listening -----------
-    server.listen(port, function () {
-      // Activate the pool requests
-      Request.activate()
+    installer.installApplication(function (err) {
+      if (err) throw err
+
+      // ----------- Make the server listening -----------
+      server.listen(port, function () {
+        // Activate the communication with friends
+        friends.activate()
 
-      logger.info('Server listening on port %d', port)
-      logger.info('Webserver: %s', constants.CONFIG.WEBSERVER.URL)
+        logger.info('Server listening on port %d', port)
+        logger.info('Webserver: %s', constants.CONFIG.WEBSERVER.URL)
 
-      app.emit('ready')
+        app.emit('ready')
+      })
     })
   })
-})
+}
 
 module.exports = app