Skip to content

Commit

Permalink
Add response compression middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
iaincollins committed Nov 11, 2024
1 parent 7b26daf commit 0fc2695
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ console.log('Loading dependancies …')
const process = require('process')
const path = require('path')
const fs = require('fs')
const cron = require('node-cron')
const { Z_SYNC_FLUSH } = require('zlib').constants
const Koa = require('koa')
const koaBodyParser = require('koa-bodyparser')
const cron = require('node-cron')
const koaCompress = require('koa-compress')

console.log('Loading libraries …')
const router = require('./router')
Expand Down Expand Up @@ -46,6 +48,16 @@ const updateGalnetNews = require('./lib/cron-tasks/galnet-news')
return next()
})

// Enable content compression
app.use(koaCompress({
filter: (content_type) => {
return /text/i.test(content_type)
},
threshold: 2048,
flush: Z_SYNC_FLUSH,
deflate: Z_SYNC_FLUSH
}))

router.get('/', (ctx) => { ctx.body = printStats() })
router.get('/api', (ctx) => { ctx.body = printStats() })
app.use(router.routes())
Expand Down
35 changes: 33 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ardent-api",
"version": "4.9.0",
"version": "4.10.0",
"description": "Ardent API provides access to data submitted to EDDN",
"main": "index.js",
"scripts": {
Expand All @@ -25,6 +25,7 @@
"dotenv": "^16.0.3",
"koa": "^2.14.2",
"koa-bodyparser": "^4.4.0",
"koa-compress": "^5.1.1",
"koa-router": "^12.0.0",
"node-cron": "^3.0.3"
},
Expand Down

0 comments on commit 0fc2695

Please sign in to comment.