Rework database storage
This commit is contained in:
parent
dde80814d0
commit
20a992da36
7 changed files with 960 additions and 237 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -36,7 +36,8 @@ typings/
|
|||
.DS_Store
|
||||
|
||||
# Database
|
||||
db/
|
||||
data/
|
||||
log.txt
|
||||
|
||||
# Session store
|
||||
sessions/
|
||||
|
|
|
@ -9,14 +9,15 @@ RUN npm install --production --silent
|
|||
COPY . .
|
||||
|
||||
ENV PORT 80
|
||||
ENV DB_EXPOSE_PORT 8080
|
||||
EXPOSE 80
|
||||
|
||||
RUN mkdir -p /data/db
|
||||
ENV DB_URL /data/db
|
||||
RUN mkdir -p /data/dbs
|
||||
ENV DB_PREFIX /data/dbs/
|
||||
|
||||
RUN mkdir -p /data/sessions
|
||||
ENV SESSION_STORE /data/sessions
|
||||
|
||||
ENV SECRET_DIRNAME /data
|
||||
|
||||
CMD npm start
|
||||
CMD Dockerstart.sh
|
10
Dockerstart.sh
Executable file
10
Dockerstart.sh
Executable file
|
@ -0,0 +1,10 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
if [ -d /data/db ]; then
|
||||
mkdir -p /data/dbs
|
||||
mv /data/db /data/dbs/users
|
||||
echo "Migrated database"
|
||||
fi
|
||||
|
||||
npm start
|
|
@ -3,9 +3,10 @@ require('dotenv').config();
|
|||
const yesNo = require('yes-no');
|
||||
|
||||
module.exports = {
|
||||
dbUrl: process.env.DB_URL || 'db',
|
||||
dbPrefix: process.env.DB_URL || 'dbs/',
|
||||
defaultFailureRedirect: process.env.DEFAULT_FAILURE_REDIRECT || '/login',
|
||||
port: Number(process.env.PORT) || 3000,
|
||||
dbExposePort: Number(process.env.DB_EXPOSE_PORT) || null,
|
||||
proxyServer: process.env.PROXY_SERVER || undefined,
|
||||
secret: process.env.SECRET || require('./secret'),
|
||||
sessionStore: process.env.SESSION_STORE || './sessions',
|
||||
|
|
18
index.js
18
index.js
|
@ -6,19 +6,26 @@ const bcrypt = require('bcrypt-nodejs');
|
|||
const flash = require('connect-flash');
|
||||
const passport = require('passport');
|
||||
const express = require('express');
|
||||
const PouchDB = require('pouchdb');
|
||||
const level = require('level');
|
||||
|
||||
const config = require('./config');
|
||||
_CC.config = config
|
||||
|
||||
if (!config.dbPrefix.startsWith('http')) {
|
||||
const mkdirp = require('mkdirp').sync
|
||||
mkdirp(config.dbPrefix)
|
||||
}
|
||||
|
||||
const PouchDB = require('pouchdb').defaults({ prefix: config.dbPrefix });
|
||||
|
||||
const logger = require('./logger');
|
||||
const { dbExposePort } = require('./config');
|
||||
|
||||
const app = express();
|
||||
app.set('base', config.base)
|
||||
app.set('trust proxy', config.trustProxy)
|
||||
|
||||
const db = new PouchDB(config.dbUrl);
|
||||
const db = new PouchDB('users');
|
||||
|
||||
passport.use('local', new LocalStrategy(
|
||||
(username, password, done) => {
|
||||
|
@ -76,3 +83,10 @@ app.set('view engine', 'pug');
|
|||
app.use(config.base, require('./routes')({ db, config }));
|
||||
|
||||
app.listen(config.port, () => logger.success('express', `Express server started on port ${config.port}!`))
|
||||
|
||||
;(() => {
|
||||
if (!dbExposePort) return
|
||||
const dbExposeApp = express()
|
||||
dbExposeApp.use('/', require('express-pouchdb')(PouchDB, { inMemoryConfig: true }));
|
||||
dbExposeApp.listen(config.dbExposePort, () => logger.success('db expose', `DB has been exposed on port ${config.dbExposePort}`))
|
||||
})()
|
||||
|
|
|
@ -22,10 +22,13 @@
|
|||
"connect-flash": "^0.1.1",
|
||||
"dotenv": "^8.2.0",
|
||||
"express": "4.17.1",
|
||||
"express-pouchdb": "^4.2.0",
|
||||
"express-session": "^1.15.6",
|
||||
"express-session-level": "^1.0.0",
|
||||
"get-product-name": "1",
|
||||
"level": "^6.0.0",
|
||||
"memdown": "^5.1.0",
|
||||
"mkdirp": "^0.5.5",
|
||||
"moment": "^2.29.1",
|
||||
"nanoid": "^3.1.16",
|
||||
"passport": "^0.4.0",
|
||||
|
|
Loading…
Reference in a new issue