env config improvement
This commit is contained in:
parent
f3cfc6abe0
commit
c02510659c
6 changed files with 51 additions and 15 deletions
37
README.md
37
README.md
|
@ -61,9 +61,42 @@ yarn
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
Add environment variables with a .env. Example:
|
Add environment variables with a .env. Example:
|
||||||
```env
|
```sh
|
||||||
SITE_TITLE="Christmas Zone"
|
## Core Settings
|
||||||
|
# Where to store databases, can be a CouchDB compatible server or directory.
|
||||||
|
DB_PREFIX=dbs/
|
||||||
|
# Where to send someone if they need to log in
|
||||||
|
DEFAULT_FAILURE_REDIRECT=/login
|
||||||
|
# Port to listen on
|
||||||
PORT=80
|
PORT=80
|
||||||
|
# Expose the internal PouchDB with CouchDB API and Fauxton browser. Mostly used for debugging. Leave empty to disable.
|
||||||
|
DB_EXPOSE_PORT=
|
||||||
|
# Proxy to send item data requests to. Leave emtpy to disable.
|
||||||
|
PROXY_SERVER=
|
||||||
|
# Secret string to store session cookies with. Automatically generated if not provided.
|
||||||
|
SECRET=
|
||||||
|
# How long a user is logged in (milliseconds). Defaults to one week.
|
||||||
|
SESSION_MAX_AGE=604800000
|
||||||
|
# The name of the site in the <title> and navigation bar
|
||||||
|
SITE_TITLE=Christmas Community
|
||||||
|
# Used when shared to home screen
|
||||||
|
SHORT_TITLE=Christmas
|
||||||
|
# The root path for forms, CSS, and a small amount of JS. Useful when proxying.
|
||||||
|
ROOT_PATH=/
|
||||||
|
# Where to trust the X-Forwarded-For header from. Defaults to "loopback". Useful for proxying to docker.
|
||||||
|
TRUST_PROXY=loopback
|
||||||
|
|
||||||
|
## Wishlist Settings
|
||||||
|
# Set to true to not allow users to have their own lists. You may want this for a birthday or wedding.
|
||||||
|
SINGLE_LIST=false
|
||||||
|
# Set to false to allow viewing wishlists without logging in
|
||||||
|
LISTS_PUBLIC=false
|
||||||
|
# Defaults to true. Set to false for legacy cards view.
|
||||||
|
TABLE=true
|
||||||
|
# Convert Amazon links to Amazon Smile links. A percentage of the profit goes to a charity of buyer's choice. Defaults to true.
|
||||||
|
SMILE=true
|
||||||
|
# Allow Markdown in item notes. Does not work with TABLE=false. Defaults to false.
|
||||||
|
MARKDOWN=false
|
||||||
```
|
```
|
||||||
|
|
||||||
## Startup
|
## Startup
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
require('dotenv').config()
|
require('dotenv').config()
|
||||||
|
|
||||||
const yesNo = require('yes-no')
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
dbPrefix: process.env.DB_PREFIX || 'dbs/',
|
dbPrefix: process.env.DB_PREFIX || 'dbs/',
|
||||||
defaultFailureRedirect: process.env.DEFAULT_FAILURE_REDIRECT || '/login',
|
defaultFailureRedirect: process.env.DEFAULT_FAILURE_REDIRECT || '/login',
|
||||||
|
@ -14,6 +12,5 @@ module.exports = {
|
||||||
shortTitle: process.env.SHORT_TITLE || 'Christmas',
|
shortTitle: process.env.SHORT_TITLE || 'Christmas',
|
||||||
wishlist: require('./wishlist'),
|
wishlist: require('./wishlist'),
|
||||||
base: (process.env.ROOT_PATH || '/').endsWith('/') ? (process.env.ROOT_PATH || '/') : `${process.env.ROOT_PATH}/`,
|
base: (process.env.ROOT_PATH || '/').endsWith('/') ? (process.env.ROOT_PATH || '/') : `${process.env.ROOT_PATH}/`,
|
||||||
trustProxy: process.env.TRUST_PROXY === 'true' ? true : process.env.TRUST_PROXY || 'loopback',
|
trustProxy: process.env.TRUST_PROXY === 'true' ? true : process.env.TRUST_PROXY || 'loopback'
|
||||||
markdown: yesNo.parse(process.env.MARKDOWN || false)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
|
const { parse: yesNo } = require('yes-no')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
singleList: yesNo(process.env.SINGLE_LIST || false),
|
||||||
|
public: yesNo(process.env.LISTS_PUBLIC || false),
|
||||||
|
table: yesNo(process.env.TABLE || true),
|
||||||
|
smile: yesNo(process.env.SMILE || true),
|
||||||
note: {
|
note: {
|
||||||
rows: Number(process.env.WISHLIST_NOTE_ROWS) || 5
|
markdown: yesNo(process.env.MARKDOWN || false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const verifyAuth = require('./verifyAuth')
|
const verifyAuth = require('./verifyAuth')
|
||||||
|
|
||||||
const publicMiddleware = () => process.env.LISTS_PUBLIC === 'true'
|
const publicMiddleware = () => global._CC.config.wishlist.public
|
||||||
? (req, res, next) => {
|
? (req, res, next) => {
|
||||||
if (!req.user) req.user = { _id: 'Unknown' }
|
if (!req.user) req.user = { _id: 'Unknown' }
|
||||||
next()
|
next()
|
||||||
|
|
|
@ -25,7 +25,7 @@ const totals = wishlist => {
|
||||||
const ValidURL = (string) => { // Ty SO
|
const ValidURL = (string) => { // Ty SO
|
||||||
try {
|
try {
|
||||||
const url = new URL(string)
|
const url = new URL(string)
|
||||||
if (process.env.SMILE !== 'false') {
|
if (global._CC.config.wishlist.smile) {
|
||||||
if (url.hostname === 'www.amazon.com') url.hostname = 'smile.amazon.com'
|
if (url.hostname === 'www.amazon.com') url.hostname = 'smile.amazon.com'
|
||||||
}
|
}
|
||||||
if (url) return url
|
if (url) return url
|
||||||
|
@ -39,7 +39,7 @@ module.exports = (db) => {
|
||||||
|
|
||||||
router.get('/', publicRoute(), async (req, res) => {
|
router.get('/', publicRoute(), async (req, res) => {
|
||||||
const docs = await db.allDocs({ include_docs: true })
|
const docs = await db.allDocs({ include_docs: true })
|
||||||
if (process.env.SINGLE_LIST === 'true') {
|
if (global._CC.config.wishlist.singleList) {
|
||||||
for (const row of docs.rows) {
|
for (const row of docs.rows) {
|
||||||
if (row.doc.admin) return res.redirect(`/wishlist/${row.doc._id}`)
|
if (row.doc.admin) return res.redirect(`/wishlist/${row.doc._id}`)
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ module.exports = (db) => {
|
||||||
router.get('/:user', publicRoute(), async (req, res) => {
|
router.get('/:user', publicRoute(), async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const dbUser = await db.get(req.params.user)
|
const dbUser = await db.get(req.params.user)
|
||||||
if (process.env.SINGLE_LIST === 'true') {
|
if (global._CC.config.wishlist.singleList) {
|
||||||
if (!dbUser.admin) {
|
if (!dbUser.admin) {
|
||||||
const docs = await db.allDocs({ include_docs: true })
|
const docs = await db.allDocs({ include_docs: true })
|
||||||
for (const row of docs.rows) {
|
for (const row of docs.rows) {
|
||||||
|
@ -63,7 +63,7 @@ module.exports = (db) => {
|
||||||
const lastCanSeeValue = wishlistReverse.find(element => (element.addedBy === req.params.user))
|
const lastCanSeeValue = wishlistReverse.find(element => (element.addedBy === req.params.user))
|
||||||
const lastCanSee = dbUser.wishlist.indexOf(lastCanSeeValue)
|
const lastCanSee = dbUser.wishlist.indexOf(lastCanSeeValue)
|
||||||
for (const item of dbUser.wishlist) {
|
for (const item of dbUser.wishlist) {
|
||||||
if (global._CC.config.markdown) item.note = DOMPurify.sanitize(marked(item.note))
|
if (global._CC.config.wishlist.note.markdown) item.note = DOMPurify.sanitize(marked(item.note))
|
||||||
}
|
}
|
||||||
res.render('wishlist', {
|
res.render('wishlist', {
|
||||||
title: `Wishlist - ${dbUser._id}`,
|
title: `Wishlist - ${dbUser._id}`,
|
||||||
|
|
|
@ -13,7 +13,7 @@ block title
|
||||||
|
|
||||||
block content
|
block content
|
||||||
script(type='data/user_id')= req.user._id
|
script(type='data/user_id')= req.user._id
|
||||||
if process.env.TABLE !== 'false'
|
if global._CC.config.wishlist.table
|
||||||
.box
|
.box
|
||||||
table.table.has-mobile-cards
|
table.table.has-mobile-cards
|
||||||
thead
|
thead
|
||||||
|
@ -45,7 +45,7 @@ block content
|
||||||
)= (item.name ? item.name : item.url)
|
)= (item.name ? item.name : item.url)
|
||||||
else
|
else
|
||||||
td.ugc(data-label='Name')= item.name
|
td.ugc(data-label='Name')= item.name
|
||||||
if _CC.config.markdown
|
if _CC.config.wishlist.note.markdown
|
||||||
td.ugc(data-label='Note')!= item.note
|
td.ugc(data-label='Note')!= item.note
|
||||||
else
|
else
|
||||||
td.ugc(data-label='Note')= item.note
|
td.ugc(data-label='Note')= item.note
|
||||||
|
@ -220,7 +220,7 @@ block print
|
||||||
span.is-block Added by: #{item.addedBy}
|
span.is-block Added by: #{item.addedBy}
|
||||||
if item.note
|
if item.note
|
||||||
.box
|
.box
|
||||||
if _CC.config.markdown
|
if _CC.config.wishlist.note.markdown
|
||||||
span.is-block.ugc!= item.note
|
span.is-block.ugc!= item.note
|
||||||
else
|
else
|
||||||
span.is-block.ugc= item.note
|
span.is-block.ugc= item.note
|
Loading…
Reference in a new issue