<commit_before>const express = require('express')
const app = express()
const bodyParser = require('body-parser')
const methodOverride = require('method-override')
const api = express.Router()
const path = require('path')

// Socket.io
const server = require('http').createServer(app)
const io = require('socket.io')(server)

// Controllers
const stories = require('./server/controllers/stories')
const prompts = require('./server/controllers/prompts')

// Define route handlers
const index = require('./routes/index')
const post = require('./routes/post')
const about = require('./routes/about')

// Get HTTP object for api calls
const HTTP = require('./server/http-common.js')

// Express config
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))

app.use(methodOverride())
app.set('port', process.env.PORT || 8000)

app.use(express.static(path.join(__dirname, '/public')))

// View engine setup
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'hbs')

// Make the db accessible to the router
app.use(function (req, res, next) {
  req.HTTP = HTTP
  next()
})

// Define and use API routes
// Stories
api.get('/stories', stories.index)
api.post('/stories', stories.create)
// Prompts
api.get('/prompts', prompts.index)

app.use('/api', api)

// App routes
app.use('/', index)
app.use('/post', post)
app.use('/about', about)

// Socket.io
server.listen(process.env.PORT || 3000)

io.on('connection', function (socket) {
  socket.on('refresh', function (data) {
    HTTP.get('/api/stories').then(function (stories) {
      socket.emit('refreshData', stories.data)
    })
  })
})

// start server
app.listen(app.get('port'), function () {
  console.log('Server started on port', app.get('port'))
})<commit_msg>socket.io for heroku<commit_after>const express = require('express')
const app = express()
const bodyParser = require('body-parser')
const methodOverride = require('method-override')
const api = express.Router()
const path = require('path')

// Controllers
const stories = require('./server/controllers/stories')
const prompts = require('./server/controllers/prompts')

// Define route handlers
const index = require('./routes/index')
const post = require('./routes/post')
const about = require('./routes/about')

// Get HTTP object for api calls
const HTTP = require('./server/http-common.js')

// Express config
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))

app.use(methodOverride())
app.set('port', process.env.PORT || 8000)

app.use(express.static(path.join(__dirname, '/public')))

// View engine setup
app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'hbs')

// Make the db accessible to the router
app.use(function (req, res, next) {
  req.HTTP = HTTP
  next()
})

// Define and use API routes
// Stories
api.get('/stories', stories.index)
api.post('/stories', stories.create)
// Prompts
api.get('/prompts', prompts.index)

app.use('/api', api)

// App routes
app.use('/', index)
app.use('/post', post)
app.use('/about', about)

// start server
const server = app.listen(app.get('port'), function () {
  console.log('Server started on port', app.get('port'))
})

// Socket.io
const io = require('socket.io')(server)

io.on('connection', function (socket) {
  socket.on('refresh', function (data) {
    HTTP.get('/api/stories').then(function (stories) {
      socket.emit('refreshData', stories.data)
    })
  })
})
{'fraction_non_alphanumeric': 0.18642586658898921, 'fraction_numerical': 0.003495484998543548, 'mean_word_length': 4.503205128205129, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1572764', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1075, 'n_words': 264}