{"size": 1274, "ext": "js", "max_stars_repo_path": "express-boilerplate/server/src/server.js", "max_stars_repo_name": "thoughtbit/node-web-starter", "max_stars_repo_stars_event_min_datetime": "2018-11-26T02:06:16.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-07T05:20:59.000Z", "max_issues_repo_path": "express-boilerplate/server/src/server.js", "max_issues_repo_name": "thoughtbit/node-web-starter", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "express-boilerplate/server/src/server.js", "max_forks_repo_name": "thoughtbit/node-web-starter", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 4, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.1636363636, "max_line_length": 96, "alphanum_fraction": 0.6891679749}
import path from 'path'
import http from 'http'
import express from 'express'
import engines from 'consolidate'
import cors from 'cors'
import bodyParser from 'body-parser'
import initializeDb from './db'
import middlewares from './middlewares'
import passport from './passport'
import routers from './routes'
import config from './config'

const app = express()

app.server = http.createServer(app)

// 3rd party middleware
app.use(cors({
  exposedHeaders: config.corsHeaders,
}))

app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json({
  limit: config.bodyLimit,
}))

// Static files
app.use(express.static(path.join(__dirname, '../public')))
app.use(['/favicon.ico', '/images*', '/media*', '/css*', '/fonts*', '/assets*'], (req, res) => {
  res.status(404).end()
})

// view engine setup
app.engine('html', engines.nunjucks)
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'html')

// connect to db
initializeDb((db) => {
  // internal middleware
  app.use(middlewares({ config, db }))

  // passport
  passport({ app, config, db })

  // api router
  app.use(routers({ config, db }))

  app.server.listen(process.env.PORT || config.port)

  console.log(`Started on port ${app.server.address().port}`)
})

export default app
