123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- const express = require('express')
- const bodyParser = require('body-parser')
- const sockjs = require('sockjs')
- const http = require('http')
- const mongoose = require('mongoose')
- const router = express.Router()
- /** Load the submodules */
- import ProjectModel from './project/model'
- /** Create the express app */
- const app = express()
- /** MongoDB middleware */
- const dbName = 'movieDB'
- const connectionString = `mongodb://localhost:27017/${dbName}`
- /** Sockjs middleware */
- const sockjsOpts = {sockjs_url: 'http://cdn.jsdelivr.net/sockjs/1.0.1/sockjs.min.js'}
- const sockjsServer = sockjs.createServer(sockjsOpts)
- sockjsServer.on('connection', function (conn) {
- conn.on('data', function (message) {
- conn.write(message)
- })
- })
- /** Bind the http server to express */
- const server = http.createServer(app)
- function f1 (req, res, next) {
- console.log('f1', req)
- next()
- }
- function f2 (req, res, next) {
- console.log('f2')
- next()
- }
- function f3 (req, res, next) {
- console.log('f3')
- res.json({message: 'Welcome to the api!'})
- }
- sockjsServer.installHandlers(server, {prefix: '/echo'})
- mongoose.connect(connectionString)
- app.use(bodyParser.json())
- app.use(bodyParser.urlencoded({ extended: true }))
- app.use(/^\/db(\/\w+)?(\/\w+)?\/?$/, [f1, f2, f3])
- /* app.get('/', function (req, res) {
- res.sendFile(`${__dirname}/index.html`)
- }) */
- server.listen(process.env.PORT || 4000)
|