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
This commit is contained in:
Wingy 2022-12-10 12:04:07 -05:00 committed by GitHub
parent 363146c331
commit 0d7d73744c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1569 changed files with 25 additions and 1159 deletions

2
.gitignore vendored
View file

@ -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
View file

@ -11,7 +11,7 @@
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/index.js",
"program": "${workspaceFolder}/src/index.js",
"env": {
"PORT": "8888"
}

View file

@ -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

View file

@ -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",

File diff suppressed because it is too large Load diff

View file

@ -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}!`))

View file

@ -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)

View file

@ -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

View file

@ -15,7 +15,7 @@ module.exports = ({ config }) => {
icons: [
{
sizes: '1280x1280',
src: '/img/logo.png'
src: `${_CC.config.base}img/logo.png`
}
]
})

View file

@ -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) => {

View file

Before

Width:  |  Height:  |  Size: 120 KiB

After

Width:  |  Height:  |  Size: 120 KiB

View file

Before

Width:  |  Height:  |  Size: 612 KiB

After

Width:  |  Height:  |  Size: 612 KiB

View file

Before

Width:  |  Height:  |  Size: 616 KiB

After

Width:  |  Height:  |  Size: 616 KiB

View file

Before

Width:  |  Height:  |  Size: 282 KiB

After

Width:  |  Height:  |  Size: 282 KiB

View file

Before

Width:  |  Height:  |  Size: 258 KiB

After

Width:  |  Height:  |  Size: 258 KiB

View file

Before

Width:  |  Height:  |  Size: 206 KiB

After

Width:  |  Height:  |  Size: 206 KiB

View file

Before

Width:  |  Height:  |  Size: 464 KiB

After

Width:  |  Height:  |  Size: 464 KiB

View file

Before

Width:  |  Height:  |  Size: 705 KiB

After

Width:  |  Height:  |  Size: 705 KiB

View file

Before

Width:  |  Height:  |  Size: 414 KiB

After

Width:  |  Height:  |  Size: 414 KiB

View file

Before

Width:  |  Height:  |  Size: 366 KiB

After

Width:  |  Height:  |  Size: 366 KiB

View file

Before

Width:  |  Height:  |  Size: 98 KiB

After

Width:  |  Height:  |  Size: 98 KiB

View file

Before

Width:  |  Height:  |  Size: 87 KiB

After

Width:  |  Height:  |  Size: 87 KiB

View file

@ -0,0 +1 @@
../../../node_modules/bulmaswatch

Some files were not shown because too many files have changed in this diff Show more