🔧 Basic configuration files for sqlite/express app
This commit is contained in:
parent
9253ce9bfc
commit
973e0f8074
8 changed files with 4131 additions and 0 deletions
35
express_defaults/city_stats_min/server/app.js
Normal file
35
express_defaults/city_stats_min/server/app.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
'use strict'
|
||||
// Server Configuration
|
||||
const app = require('express')()
|
||||
// const json = require('express').json
|
||||
// const cors = require('cors')
|
||||
// const bodyParser = require('body-parser')
|
||||
const router = require('../routes/')
|
||||
|
||||
// Logger configuration
|
||||
const pino = require('pino')
|
||||
const logger = require('pino-http')({
|
||||
logger: pino(pino.destination('/var/log/citystats/log.json')),
|
||||
})
|
||||
|
||||
// App configuration
|
||||
const port = process.env.PORT || 5000
|
||||
// app.use(
|
||||
// cors({
|
||||
// origin: '*',
|
||||
// methods: 'GET',
|
||||
// credentials: true,
|
||||
// }),
|
||||
// )
|
||||
// app.use(bodyParser.urlencoded({ extended: false }))
|
||||
// app.use(json())
|
||||
app.use(logger)
|
||||
|
||||
// Main routes
|
||||
app.use('/', router)
|
||||
|
||||
// Initialize Server...
|
||||
const server = app.listen(port, () =>
|
||||
console.log(`serving sqlite database as JSON on port: ${port}`))
|
||||
|
||||
module.exports = server
|
||||
31
express_defaults/city_stats_min/server/index.js
Normal file
31
express_defaults/city_stats_min/server/index.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
'use strict'
|
||||
// Server Connection
|
||||
const server = require('./app.js')
|
||||
|
||||
let connections = []
|
||||
server.on('connection', connection => {
|
||||
connections.push(connection)
|
||||
connection.on('close', () =>
|
||||
(connections = connections.filter(curr =>
|
||||
curr !== connection)),
|
||||
)
|
||||
})
|
||||
|
||||
const shutDown = () => {
|
||||
server.close(() => {
|
||||
console.log('closing server with exit code 0...')
|
||||
process.exit(0)
|
||||
})
|
||||
setTimeout(() => {
|
||||
console.error('failure to close server properly...')
|
||||
console.error('exit code 1...')
|
||||
process.exit(1)
|
||||
}, 10000)
|
||||
connections.forEach(curr => curr.end())
|
||||
setTimeout(() =>
|
||||
connections.forEach(curr =>
|
||||
curr.destroy()), 5000)
|
||||
}
|
||||
|
||||
process.on('SIGTERM', shutDown)
|
||||
process.on('SIGINT', shutDown)
|
||||
Loading…
Add table
Add a link
Reference in a new issue