const express = require('express') const bodyParser = require('body-parser') const http = require('http') // const oauthserver = require('oauth2-server') const mongoose = require('mongoose') /** Load the submodules */ import project from './project/route' /** Create the express app */ const app = express() /** MongoDB middleware */ const dbName = 'AutoMateDB' const connectionString = `mongodb://localhost:27017/${dbName}` /** Bind the http server to express */ const server = http.createServer(app) /** Connect the middleware to the server */ mongoose.connect(connectionString) 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() } app.use(bodyParser.json()) app.use(bodyParser.urlencoded({ extended: true })) /* app.oauth = oauthserver({ model: {}, grants: ['password'], debug: true }) app.all('/oauth/token', app.oauth.grant()) app.get('/', app.oauth.authorise(), (req, res) => { res.send('Secret area') }) app.use(app.oauth.errorHandler()) */ app.get('/', welcomeRouter) app.use('/project', project) app.use(/.*/, errorRouter) server.listen(process.env.PORT || 4100)