123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import * as debugStuff from 'debug'
- const debug = debugStuff.debug('dbApiServer')
- debug('Starting the dbApiServer')
- const express = require('express')
- debug(' - Loaded express')
- const bodyParser = require('body-parser')
- debug(' - Loaded bodyParser')
- const http = require('http')
- debug(' - Loaded http')
- // const oauthserver = require('oauth2-server')
- const mongoose = require('mongoose')
- debug(' - Loaded mongoose')
- /** Create the express app */
- const app = express()
- debug('Created app')
- /** Bind the http server to express */
- const server = http.createServer(app)
- debug('Created server')
- /** MongoDB middleware */
- const dbName = 'AutoMateDB'
- const connectionString = `mongodb://localhost:27017/${dbName}`
- /** Connect the middleware to the server */
- mongoose.connect(connectionString)
- debug('Connected DB')
- function welcomeRouter (req, res) {
- res.status(200)
- res.json({ message: 'Welcome to the AutoMate DB API!' })
- }
- function errorRouter (req, res) {
- res.status(404)
- res.send()
- }
- debug('Defined default routers')
- app.use(bodyParser.json())
- app.use(bodyParser.urlencoded({ extended: true }))
- /** Load the submodules */
- // import projects from './projects/route'
- import routeGenModel from './routeGenModel'
- app.get('/', welcomeRouter)
- // app.use('/projects', projects)
- app.use(/.*/, errorRouter)
- debug('Configured app')
- const port = process.env.PORT || 4100
- server.listen(port)
- debug('Started server on port %s', port)
|