Refactor: move src to folder (#63)
* move all source code to src/ * replace express response patch with middleware * fix readdir not looking in src * fix stray redirect * add base to manifest * remove secret.txt from src/config/secret * add src/config/secret/secret.txt to gitignore
2
.gitignore
vendored
|
@ -41,6 +41,6 @@ log.txt
|
|||
|
||||
# Session store
|
||||
sessions/
|
||||
config/secret/secret.txt
|
||||
src/config/secret/secret.txt
|
||||
|
||||
package-lock.json
|
2
.vscode/launch.json
vendored
|
@ -11,7 +11,7 @@
|
|||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"program": "${workspaceFolder}/index.js",
|
||||
"program": "${workspaceFolder}/src/index.js",
|
||||
"env": {
|
||||
"PORT": "8888"
|
||||
}
|
||||
|
|
|
@ -9,4 +9,4 @@ services:
|
|||
ports:
|
||||
- 80:80
|
||||
- 9229:9229
|
||||
command: node --inspect=0.0.0.0:9229 index.js
|
||||
command: node --inspect=0.0.0.0:9229 src/index.js
|
|
@ -2,12 +2,11 @@
|
|||
"name": "christmas-community",
|
||||
"version": "1.30.1",
|
||||
"description": "Christmas lists for communities",
|
||||
"main": "main.js",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
"postinstall": "cp patched-express-response.js node_modules/express/lib/response.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node manager.js",
|
||||
"dev": "nodemon index.js"
|
||||
"start": "node src/manager.js",
|
||||
"dev": "nodemon"
|
||||
},
|
||||
"author": "Wingysam <wingysam+git@gmail.com>",
|
||||
"license": "AGPL-3.0",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
global._CC = { require }
|
||||
|
||||
_CC.package = require('./package.json')
|
||||
_CC.package = require('../package.json')
|
||||
|
||||
const PouchSession = require('session-pouchdb-store')
|
||||
const LocalStrategy = require('passport-local').Strategy
|
||||
|
@ -10,6 +10,7 @@ const flash = require('connect-flash')
|
|||
const passport = require('passport')
|
||||
const fetch = require('node-fetch')
|
||||
const express = require('express')
|
||||
const path = require('path')
|
||||
|
||||
_CC._ = require('lodash')
|
||||
_CC.moment = require('moment/min/moment-with-locales')
|
||||
|
@ -81,6 +82,17 @@ passport.deserializeUser((user, callback) => {
|
|||
.catch(() => callback(null, null))
|
||||
})
|
||||
|
||||
// https://stackoverflow.com/a/54426950
|
||||
app.use((req, res, next) => {
|
||||
const redirector = res.redirect
|
||||
res.redirect = function (url) {
|
||||
const base = this.req.app.set('base')
|
||||
if (base && url.startsWith('/')) url = base + url.substr(1)
|
||||
redirector.call(this, url)
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
app.use(require('body-parser').urlencoded({ extended: true }))
|
||||
app.use(session({
|
||||
secret: config.secret,
|
||||
|
@ -104,6 +116,7 @@ app.use((req, res, next) => {
|
|||
})
|
||||
|
||||
app.set('view engine', 'pug')
|
||||
app.set('views', path.join(__dirname, 'views'))
|
||||
app.use(config.base, require('./routes')({ db, config }))
|
||||
|
||||
app.listen(config.port, () => logger.success('express', `Express server started on port ${config.port}!`))
|
|
@ -19,7 +19,7 @@ async function updateGPD () {
|
|||
;(async () => {
|
||||
let cc = null
|
||||
function spawnCC () {
|
||||
cc = spawn('node', ['index.js'], { env: process.env })
|
||||
cc = spawn('node', ['src/index.js'], { env: process.env })
|
||||
cc.on('exit', spawnCC)
|
||||
cc.stdout.pipe(process.stdout)
|
||||
cc.stderr.pipe(process.stderr)
|
|
@ -11,7 +11,7 @@ module.exports = ({ db, config }) => {
|
|||
|
||||
const { rows } = await db.allDocs({ include_docs: true })
|
||||
|
||||
const unfilteredPool = await fs.readdir('static/img/default-pfps')
|
||||
const unfilteredPool = await fs.readdir('src/static/img/default-pfps')
|
||||
const filteredPool = unfilteredPool.filter(file => !rows.find(row => row.doc.pfp === `${_CC.config.base}img/default-pfps/${file}`))
|
||||
const pool = filteredPool.length ? filteredPool : unfilteredPool
|
||||
|
|
@ -15,7 +15,7 @@ module.exports = ({ config }) => {
|
|||
icons: [
|
||||
{
|
||||
sizes: '1280x1280',
|
||||
src: '/img/logo.png'
|
||||
src: `${_CC.config.base}img/logo.png`
|
||||
}
|
||||
]
|
||||
})
|
|
@ -19,7 +19,7 @@ module.exports = ({ db, config, ensurePfp }) => {
|
|||
} else {
|
||||
req.flash('error', _CC.lang('PROFILE_SAVE_PFP_DISABLED'))
|
||||
}
|
||||
res.redirect(`${_CC.config.base}profile`)
|
||||
res.redirect('/profile')
|
||||
})
|
||||
|
||||
router.get('/password', verifyAuth(), async (req, res) => {
|
Before Width: | Height: | Size: 120 KiB After Width: | Height: | Size: 120 KiB |
Before Width: | Height: | Size: 612 KiB After Width: | Height: | Size: 612 KiB |
Before Width: | Height: | Size: 616 KiB After Width: | Height: | Size: 616 KiB |
Before Width: | Height: | Size: 282 KiB After Width: | Height: | Size: 282 KiB |
Before Width: | Height: | Size: 258 KiB After Width: | Height: | Size: 258 KiB |
Before Width: | Height: | Size: 206 KiB After Width: | Height: | Size: 206 KiB |
Before Width: | Height: | Size: 464 KiB After Width: | Height: | Size: 464 KiB |
Before Width: | Height: | Size: 705 KiB After Width: | Height: | Size: 705 KiB |
Before Width: | Height: | Size: 414 KiB After Width: | Height: | Size: 414 KiB |
Before Width: | Height: | Size: 366 KiB After Width: | Height: | Size: 366 KiB |
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 98 KiB |
Before Width: | Height: | Size: 87 KiB After Width: | Height: | Size: 87 KiB |
1
src/static/libraries/bulmaswatch
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../../node_modules/bulmaswatch
|