Browse Source

WIP Add DB caching

main
Yarmo Mackenbach 11 months ago
parent
commit
8d251c9a14
  1. 1
      .env
  2. 2
      Dockerfile
  3. 17
      index.js
  4. 28
      package-lock.json
  5. 1
      package.json

1
.env

@ -0,0 +1 @@
DB_PATH=./data

2
Dockerfile

@ -11,5 +11,7 @@ RUN npm install --production
# Bundle app source
COPY . .
VOLUME /data
EXPOSE 3000
CMD [ "node", "index.js" ]

17
index.js

@ -6,6 +6,23 @@ require('dotenv').config()
app.set('env', process.env.NODE_ENV || "production")
app.set('view engine', 'pug')
app.set('port', process.env.PORT || 3000)
app.set('db_path', process.env.DB_PATH || "/data")
if (!fs.existsSync(app.get('db_path'))) {
fs.mkdirSync(app.get('db_path'))
}
const db_path_file = path.join(app.get('db_path'), 'db.json')
if (!fs.existsSync(db_path_file)) {
fs.closeSync(fs.openSync(db_path_file, 'w'));
}
const adapter = new FileSync(db_path_file)
const db = low(adapter)
db.defaults({ posts: [] })
.write()
app.use((req, res, next) => {
req.db = db
})
app.use('/', require('./routes/main'))
app.use('/', require('./routes/static'))

28
package-lock.json

@ -679,8 +679,7 @@
"graceful-fs": {
"version": "4.2.4",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz",
"integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==",
"dev": true
"integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw=="
},
"has-flag": {
"version": "3.0.0",
@ -939,6 +938,18 @@
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz",
"integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA=="
},
"lowdb": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/lowdb/-/lowdb-1.0.0.tgz",
"integrity": "sha512-2+x8esE/Wb9SQ1F9IHaYWfsC9FIecLOPrK4g17FGEayjUWH172H6nwicRovGvSE2CPZouc2MCIqCI7h9d+GftQ==",
"requires": {
"graceful-fs": "^4.1.3",
"is-promise": "^2.1.0",
"lodash": "4",
"pify": "^3.0.0",
"steno": "^0.4.1"
}
},
"lowercase-keys": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.1.tgz",
@ -1188,6 +1199,11 @@
"integrity": "sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==",
"dev": true
},
"pify": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz",
"integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY="
},
"prepend-http": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-2.0.0.tgz",
@ -1522,6 +1538,14 @@
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
"integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
},
"steno": {
"version": "0.4.4",
"resolved": "https://registry.npmjs.org/steno/-/steno-0.4.4.tgz",
"integrity": "sha1-BxEFvfwobmYVwEA8J+nXtdy4Vcs=",
"requires": {
"graceful-fs": "^4.1.3"
}
},
"string-width": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz",

1
package.json

@ -22,6 +22,7 @@
"feed": "^4.2.1",
"jstransformer-markdown-it": "^2.1.0",
"lodash": "^4.17.20",
"lowdb": "^1.0.0",
"luxon": "^1.25.0",
"markdown-it-anchor": "^5.3.0",
"markdown-it-table-of-contents": "^0.4.4",

Loading…
Cancel
Save