-if ([ 'dev', 'test'].indexOf(process.env.NODE_ENV) !== -1) {
+import { isTestInstance } from './server/helpers/core-utils'
+
+if (isTestInstance()) {
require('source-map-support').install()
}
// ----------- Node modules -----------
-import bodyParser = require('body-parser')
-import express = require('express')
+import * as bodyParser from 'body-parser'
+import * as express from 'express'
+// FIXME: cannot import express-validator
const expressValidator = require('express-validator')
-import http = require('http')
-import morgan = require('morgan')
-import path = require('path')
-import bittorrentTracker = require('bittorrent-tracker')
+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'
const TrackerServer = bittorrentTracker.Server
import { API_VERSION, CONFIG } from './server/initializers/constants'
// Initialize database and models
import { database as db } from './server/initializers/database'
-db.init(false, onDatabaseInitDone)
+db.init(false).then(() => onDatabaseInitDone())
// ----------- Checker -----------
import { checkMissedConfig, checkFFmpeg, checkConfig } from './server/initializers/checker'
if (missed.length !== 0) {
throw new Error('Miss some configurations keys : ' + missed)
}
-checkFFmpeg(function (err) {
- if (err) {
- throw err
- }
-})
+checkFFmpeg()
const errorMessage = checkConfig()
if (errorMessage !== null) {
// ----------- App -----------
+// Enable cors for develop
+if (isTestInstance()) {
+ app.use(cors({
+ origin: 'http://localhost:3000',
+ credentials: true
+ }))
+}
+
// For the logger
app.use(morgan('combined', {
stream: { write: logger.info }
function onDatabaseInitDone () {
const port = CONFIG.LISTEN.PORT
// Run the migration scripts if needed
- migrate(function (err) {
- if (err) throw err
-
- installApplication(function (err) {
- if (err) throw err
-
+ migrate()
+ .then(() => {
+ return installApplication()
+ })
+ .then(() => {
// ----------- Make the server listening -----------
server.listen(port, function () {
// Activate the communication with friends
logger.info('Webserver: %s', CONFIG.WEBSERVER.URL)
})
})
- })
}