import * as express from 'express' ; import * as http from 'http' ; import * as bodyParser from 'body-parser' ; import * as serveStatic from 'serve-static' ; import * as path from 'path' ; import * as mongoose from 'mongoose' ; import { Rest } from './rest' ; declare var process , __dirname , global ; export class Backend { public app : any ; public server : any ; private mongo : any ; private rest : any ; private root : string ; constructor ( ) { this . app = express ( ) ; this . app . use ( bodyParser . json ( ) ) ; this . routes ( ) ; this . server = http . createServer ( this . app ) ; this . databases ( ) ; } private routes ( ) { let router ; router = express . Router ( ) ; const root = path . join ( path . resolve ( __dirname , '../../target' ) ) ; this . app . use ( '/assets' , serveStatic ( path . resolve ( root , 'assets' ) ) ) ; this . app . use ( '/favicon.ico' , serveStatic ( path . resolve ( root , 'favicon.ico' ) ) ) ; this . rest = new Rest ( ) ; this . app . use ( '/rest' , this . rest . router ) ; router . get ( '/' , ( request , result ) => { result . sendFile ( path . join ( root , '/index.html' ) ) ; } ) ; this . app . use ( '*' , router ) ; } private databases ( ) { const MONGODB_URI = process . env . MONGODB_URI || 'mongodb://localhost/angular-mean-starter' ; this . mongo = mongoose . connect ( MONGODB_URI , { useMongoClient : true } ) ; ( < any > mongoose ) . Promise = global . Promise ; } }