Browse Source

refactor: moved server content to /server

pull/89/head
NGPixel 7 years ago
parent
commit
d4b73be1e7
97 changed files with 7451 additions and 72 deletions
  1. 0
      .build/.deployexclude
  2. 5
      .build/_preinit.js
  3. 1
      .eslintrc.json
  4. 8
      .gitignore
  5. 2
      .travis.yml
  6. 14
      fuse.js
  7. 4
      package.json
  8. 24
      server/agent.js
  9. 0
      server/app/content/create.md
  10. 0
      server/app/data.yml
  11. 0
      server/app/regex.js
  12. 18
      server/configure.js
  13. 0
      server/controllers/admin.js
  14. 0
      server/controllers/auth.js
  15. 6
      server/controllers/pages.js
  16. 0
      server/controllers/uploads.js
  17. 0
      server/controllers/ws.js
  18. 20
      server/index.js
  19. 12
      server/init.js
  20. 0
      server/libs/auth.js
  21. 7
      server/libs/config.js
  22. 2
      server/libs/db.js
  23. 20
      server/libs/entries.js
  24. 4
      server/libs/git.js
  25. 0
      server/libs/local.js
  26. 0
      server/libs/logger.js
  27. 0
      server/libs/markdown.js
  28. 0
      server/libs/rights.js
  29. 0
      server/libs/search-index/index.js
  30. 0
      server/libs/search-index/siUtil.js
  31. 4
      server/libs/search.js
  32. 0
      server/libs/system.js
  33. 0
      server/libs/uploads-agent.js
  34. 0
      server/libs/uploads.js
  35. 0
      server/libs/winston-transports/bugsnag.js
  36. 0
      server/libs/winston-transports/rollbar.js
  37. 0
      server/libs/winston-transports/sentry.js
  38. 0
      server/locales/de/auth.json
  39. 0
      server/locales/de/common.json
  40. 0
      server/locales/en/auth.json
  41. 0
      server/locales/en/common.json
  42. 0
      server/locales/es/auth.json
  43. 0
      server/locales/es/common.json
  44. 0
      server/locales/fr/auth.json
  45. 0
      server/locales/fr/common.json
  46. 0
      server/locales/ko/auth.json
  47. 0
      server/locales/ko/common.json
  48. 0
      server/locales/pt/auth.json
  49. 0
      server/locales/pt/common.json
  50. 0
      server/locales/ru/auth.json
  51. 0
      server/locales/ru/common.json
  52. 0
      server/middlewares/auth.js
  53. 0
      server/middlewares/flash.js
  54. 0
      server/middlewares/security.js
  55. 0
      server/middlewares/seo.js
  56. 0
      server/models/bruteforce.js
  57. 0
      server/models/entry.js
  58. 0
      server/models/upl-file.js
  59. 0
      server/models/upl-folder.js
  60. 0
      server/models/user.js
  61. 0
      server/views/auth/login.pug
  62. 0
      server/views/common/alerts.pug
  63. 0
      server/views/common/footer.pug
  64. 0
      server/views/common/header.pug
  65. 0
      server/views/common/mixins.pug
  66. 0
      server/views/configure/index.pug
  67. 0
      server/views/error-forbidden.pug
  68. 0
      server/views/error-notexist.pug
  69. 0
      server/views/error.pug
  70. 0
      server/views/layout.pug
  71. 0
      server/views/modals/admin-createuser.pug
  72. 0
      server/views/modals/admin-deleteuser.pug
  73. 0
      server/views/modals/admin-upgrade.pug
  74. 0
      server/views/modals/create-discard.pug
  75. 0
      server/views/modals/create.pug
  76. 0
      server/views/modals/edit-discard.pug
  77. 0
      server/views/modals/editor-codeblock.pug
  78. 0
      server/views/modals/editor-file.pug
  79. 0
      server/views/modals/editor-image.pug
  80. 0
      server/views/modals/editor-link.pug
  81. 0
      server/views/modals/editor-video.pug
  82. 0
      server/views/modals/move.pug
  83. 0
      server/views/pages/admin/_layout.pug
  84. 0
      server/views/pages/admin/profile.pug
  85. 0
      server/views/pages/admin/settings.pug
  86. 0
      server/views/pages/admin/stats.pug
  87. 0
      server/views/pages/admin/users-edit.pug
  88. 0
      server/views/pages/admin/users.pug
  89. 0
      server/views/pages/all.pug
  90. 0
      server/views/pages/create.pug
  91. 0
      server/views/pages/edit.pug
  92. 0
      server/views/pages/source.pug
  93. 0
      server/views/pages/view.pug
  94. 0
      server/views/pages/welcome.pug
  95. 2
      test/lint.js
  96. 2
      wiki.js
  97. 7368
      yarn.lock

.deployexclude → .build/.deployexclude

5
.build/_preinit.js

@ -0,0 +1,5 @@
window.MathJax = {
root: '/js/mathjax',
delayStartupUntil: 'configured'
}
;

1
.eslintrc.json

@ -27,6 +27,7 @@
"ws": true,
"Mongoose": true,
"ROOTPATH": true,
"SERVERPATH": true,
"IS_DEBUG": true,
"PROCNAME": true
}

8
.gitignore

@ -1,7 +1,6 @@
# Logs
logs
*.log
npm-debug.log*
/logs
# Deployment builds
@ -11,11 +10,11 @@ dist
node_modules
npm/node_modules
# Optional npm cache directory
# NPM / Yarn
.npm
# Optional REPL history
.yarn.lock
.node_repl_history
npm-debug.log*
# NewRelic APM
newrelic.js
@ -25,7 +24,6 @@ newrelic.js
# Fusebox
.fusebox
.build
# Config Files
config.yml

2
.travis.yml

@ -20,7 +20,7 @@ before_script:
- npm install -g snyk
- snyk auth $SNYK_TOKEN
before_deploy:
- tar -czf wiki-js.tar.gz * -X .deployexclude
- tar -czf wiki-js.tar.gz * -X .build/.deployexclude
- snyk monitor
deploy:
provider: releases

14
fuse.js

@ -213,15 +213,7 @@ globalTasks.then(() => {
exec: (args.i) ? 'node --inspect server' : 'node server',
ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/'],
ext: 'js json',
watch: [
'controllers',
'libs',
'locales',
'middlewares',
'models',
'agent.js',
'server.js'
],
watch: ['server'],
env: { 'NODE_ENV': 'development' }
})
}, 1000)
@ -258,9 +250,7 @@ globalTasks.then(() => {
exec: 'node wiki configure',
ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/'],
ext: 'js json',
watch: [
'configure.js'
],
watch: ['server/configure.js'],
env: { 'NODE_ENV': 'development' }
})
}, 1000)

4
package.json

@ -60,7 +60,7 @@
"file-type": "^4.2.0",
"filesize.js": "^1.0.2",
"follow-redirects": "^1.2.3",
"fs-extra": "^2.1.2",
"fs-extra": "^3.0.0",
"git-wrapper2-promise": "^0.2.9",
"highlight.js": "^9.11.0",
"i18next": "^8.0.0",
@ -145,7 +145,7 @@
"nodemon": "latest",
"pug-lint": "latest",
"snyk": "latest",
"standard": "^10.0.2",
"standard": "latest",
"sticky-js": "^1.2.0",
"twemoji-awesome": "^1.0.6",
"uglify-js": "latest",

agent.js → server/agent.js

@ -4,8 +4,13 @@
// Licensed under AGPLv3
// ===========================================
const path = require('path')
const ROOTPATH = process.cwd()
const SERVERPATH = path.join(ROOTPATH, 'server')
global.PROCNAME = 'AGENT'
global.ROOTPATH = __dirname
global.ROOTPATH = ROOTPATH
global.SERVERPATH = SERVERPATH
global.IS_DEBUG = process.env.NODE_ENV === 'development'
let appconf = require('./libs/config')()
@ -34,20 +39,19 @@ global.mark = require('./libs/markdown')
// Load modules
// ----------------------------------------
var moment = require('moment')
var Promise = require('bluebird')
var fs = Promise.promisifyAll(require('fs-extra'))
var klaw = require('klaw')
var path = require('path')
var Cron = require('cron').CronJob
const moment = require('moment')
const Promise = require('bluebird')
const fs = Promise.promisifyAll(require('fs-extra'))
const klaw = require('klaw')
const Cron = require('cron').CronJob
// ----------------------------------------
// Start Cron
// ----------------------------------------
var job
var jobIsBusy = false
var jobUplWatchStarted = false
let job
let jobIsBusy = false
let jobUplWatchStarted = false
db.onReady.then(() => {
return db.Entry.remove({})

client/content/create.md → server/app/content/create.md

app/data.yml → server/app/data.yml

app/regex.js → server/app/regex.js

configure.js → server/configure.js

@ -1,7 +1,10 @@
'use strict'
module.exports = (port, spinner) => {
const ROOTPATH = __dirname
const path = require('path')
const ROOTPATH = process.cwd()
const SERVERPATH = path.join(ROOTPATH, 'server')
const IS_DEBUG = process.env.NODE_ENV === 'development'
// ----------------------------------------
@ -13,7 +16,6 @@ module.exports = (port, spinner) => {
const express = require('express')
const favicon = require('serve-favicon')
const http = require('http')
const path = require('path')
const Promise = require('bluebird')
const fs = Promise.promisifyAll(require('fs-extra'))
const yaml = require('js-yaml')
@ -39,7 +41,7 @@ module.exports = (port, spinner) => {
// View Engine Setup
// ----------------------------------------
app.set('views', path.join(ROOTPATH, 'views'))
app.set('views', path.join(SERVERPATH, 'views'))
app.set('view engine', 'pug')
app.use(bodyParser.json())
@ -55,8 +57,8 @@ module.exports = (port, spinner) => {
let langs = []
let conf = {}
try {
langs = yaml.safeLoad(fs.readFileSync('./app/data.yml', 'utf8')).langs
conf = yaml.safeLoad(fs.readFileSync('./config.yml', 'utf8'))
langs = yaml.safeLoad(fs.readFileSync(path.join(SERVERPATH, 'app/data.yml'), 'utf8')).langs
conf = yaml.safeLoad(fs.readFileSync(path.join(ROOTPATH, 'config.yml'), 'utf8'))
} catch (err) {
console.error(err)
}
@ -304,7 +306,7 @@ module.exports = (port, spinner) => {
}
})
}),
fs.readFileAsync('./config.yml', 'utf8').then(confRaw => {
fs.readFileAsync(path.join(ROOTPATH, 'config.yml'), 'utf8').then(confRaw => {
let conf = yaml.safeLoad(confRaw)
conf.title = req.body.title
conf.host = req.body.host
@ -347,12 +349,12 @@ module.exports = (port, spinner) => {
return crypto.randomBytesAsync(32).then(buf => {
conf.sessionSecret = buf.toString('hex')
confRaw = yaml.safeDump(conf)
return fs.writeFileAsync('./config.yml', confRaw)
return fs.writeFileAsync(path.join(ROOTPATH, 'config.yml'), confRaw)
})
})
).then(() => {
if (process.env.IS_HEROKU) {
return fs.outputJsonAsync('./app/heroku.json', { configured: true })
return fs.outputJsonAsync(path.join(SERVERPATH, 'app/heroku.json'), { configured: true })
} else {
return true
}

controllers/admin.js → server/controllers/admin.js

controllers/auth.js → server/controllers/auth.js

controllers/pages.js → server/controllers/pages.js

@ -50,7 +50,7 @@ router.put('/edit/*', (req, res, next) => {
let safePath = entries.parsePath(_.replace(req.path, '/edit', ''))
entries.update(safePath, req.body.markdown).then(() => {
entries.update(safePath, req.body.markdown, req.user).then(() => {
return res.json({
ok: true
}) || true
@ -118,7 +118,7 @@ router.put('/create/*', (req, res, next) => {
let safePath = entries.parsePath(_.replace(req.path, '/create', ''))
entries.create(safePath, req.body.markdown).then(() => {
entries.create(safePath, req.body.markdown, req.user).then(() => {
return res.json({
ok: true
}) || true
@ -232,7 +232,7 @@ router.put('/*', (req, res, next) => {
let safeNewPath = entries.parsePath(req.body.move)
entries.move(safePath, safeNewPath).then(() => {
entries.move(safePath, safeNewPath, req.user).then(() => {
res.json({
ok: true
})

controllers/uploads.js → server/controllers/uploads.js

controllers/ws.js → server/controllers/ws.js

server.js → server/index.js

@ -6,14 +6,15 @@
// Licensed under AGPLv3
// ===========================================
const path = require('path')
const ROOTPATH = process.cwd()
const SERVERPATH = path.join(ROOTPATH, 'server')
global.PROCNAME = 'SERVER'
global.ROOTPATH = __dirname
global.ROOTPATH = ROOTPATH
global.SERVERPATH = SERVERPATH
global.IS_DEBUG = process.env.NODE_ENV === 'development'
if (IS_DEBUG) {
try { require('newrelic') } catch (err) {}
}
process.env.VIPS_WARNING = false
let appconf = require('./libs/config')()
@ -57,13 +58,12 @@ const i18nextBackend = require('i18next-node-fs-backend')
const i18nextMw = require('i18next-express-middleware')
const passport = require('passport')
const passportSocketIo = require('passport.socketio')
const path = require('path')
const session = require('express-session')
const SessionMongoStore = require('connect-mongo')(session)
const socketio = require('socket.io')
var mw = autoload(path.join(ROOTPATH, '/middlewares'))
var ctrl = autoload(path.join(ROOTPATH, '/controllers'))
var mw = autoload(path.join(SERVERPATH, '/middlewares'))
var ctrl = autoload(path.join(SERVERPATH, '/controllers'))
// ----------------------------------------
// Define Express App
@ -141,7 +141,7 @@ lang
// ----------------------------------------
app.use(i18nextMw.handle(lang))
app.set('views', path.join(ROOTPATH, 'views'))
app.set('views', path.join(SERVERPATH, 'views'))
app.set('view engine', 'pug')
app.use(bodyParser.json())
@ -241,7 +241,7 @@ io.on('connection', ctrl.ws)
// Start child processes
// ----------------------------------------
let bgAgent = fork('agent.js')
let bgAgent = fork(path.join(SERVERPATH, 'agent.js'))
bgAgent.on('message', m => {
if (!m.action) {

init.js → server/init.js

@ -6,6 +6,8 @@ const pm2 = Promise.promisifyAll(require('pm2'))
const ora = require('ora')
const path = require('path')
const ROOTPATH = process.cwd()
module.exports = {
/**
* Detect the most appropriate start mode
@ -22,14 +24,14 @@ module.exports = {
*/
startInBackgroundMode: function () {
let spinner = ora('Initializing...').start()
return fs.emptyDirAsync(path.join(__dirname, './logs')).then(() => {
return fs.emptyDirAsync(path.join(ROOTPATH, './logs')).then(() => {
return pm2.connectAsync().then(() => {
return pm2.startAsync({
name: 'wiki',
script: 'server.js',
cwd: __dirname,
output: path.join(__dirname, './logs/wiki-output.log'),
error: path.join(__dirname, './logs/wiki-error.log'),
script: 'server',
cwd: ROOTPATH,
output: path.join(ROOTPATH, './logs/wiki-output.log'),
error: path.join(ROOTPATH, './logs/wiki-error.log'),
minUptime: 5000,
maxRestarts: 5
}).then(() => {

libs/auth.js → server/libs/auth.js

libs/config.js → server/libs/config.js

@ -3,6 +3,7 @@
const fs = require('fs')
const yaml = require('js-yaml')
const _ = require('lodash')
const path = require('path')
/**
* Load Application Configuration
@ -12,9 +13,9 @@ const _ = require('lodash')
*/
module.exports = (confPaths) => {
confPaths = _.defaults(confPaths, {
config: './config.yml',
data: './app/data.yml',
dataRegex: '../app/regex.js'
config: path.join(ROOTPATH, 'config.yml'),
data: path.join(SERVERPATH, 'app/data.yml'),
dataRegex: path.join(SERVERPATH, 'app/regex.js')
})
let appconfig = {}

libs/db.js → server/libs/db.js

@ -23,7 +23,7 @@ module.exports = {
let self = this
global.Mongoose = modb
let dbModelsPath = path.resolve(ROOTPATH, 'models')
let dbModelsPath = path.join(SERVERPATH, 'models')
modb.Promise = require('bluebird')

libs/entries.js → server/libs/entries.js

@ -249,15 +249,16 @@ module.exports = {
*
* @param {String} entryPath The entry path
* @param {String} contents The markdown-formatted contents
* @param {Object} author The author user object
* @return {Promise<Boolean>} True on success, false on failure
*/
update (entryPath, contents) {
update (entryPath, contents, author) {
let self = this
let fpath = self.getFullPath(entryPath)
return fs.statAsync(fpath).then((st) => {
if (st.isFile()) {
return self.makePersistent(entryPath, contents).then(() => {
return self.makePersistent(entryPath, contents, author).then(() => {
return self.updateCache(entryPath).then(entry => {
return search.add(entry)
})
@ -353,14 +354,15 @@ module.exports = {
*
* @param {String} entryPath The entry path
* @param {String} contents The markdown-formatted contents
* @param {Object} author The author user object
* @return {Promise<Boolean>} True on success, false on failure
*/
create (entryPath, contents) {
create (entryPath, contents, author) {
let self = this
return self.exists(entryPath).then((docExists) => {
if (!docExists) {
return self.makePersistent(entryPath, contents).then(() => {
return self.makePersistent(entryPath, contents, author).then(() => {
return self.updateCache(entryPath).then(entry => {
return search.add(entry)
})
@ -379,14 +381,15 @@ module.exports = {
*
* @param {String} entryPath The entry path
* @param {String} contents The markdown-formatted contents
* @param {Object} author The author user object
* @return {Promise<Boolean>} True on success, false on failure
*/
makePersistent (entryPath, contents) {
makePersistent (entryPath, contents, author) {
let self = this
let fpath = self.getFullPath(entryPath)
return fs.outputFileAsync(fpath, contents).then(() => {
return git.commitDocument(entryPath)
return git.commitDocument(entryPath, author)
})
},
@ -395,9 +398,10 @@ module.exports = {
*
* @param {String} entryPath The current entry path
* @param {String} newEntryPath The new entry path
* @param {Object} author The author user object
* @return {Promise} Promise of the operation
*/
move (entryPath, newEntryPath) {
move (entryPath, newEntryPath, author) {
let self = this
if (_.isEmpty(entryPath) || entryPath === 'home') {
@ -405,7 +409,7 @@ module.exports = {
}
return git.moveDocument(entryPath, newEntryPath).then(() => {
return git.commitDocument(newEntryPath).then(() => {
return git.commitDocument(newEntryPath, author).then(() => {
// Delete old cache version
let oldEntryCachePath = self.getCachePath(entryPath)

libs/git.js → server/libs/git.js

@ -195,7 +195,7 @@ module.exports = {
* @param {String} entryPath The entry path
* @return {Promise} Resolve on commit success
*/
commitDocument (entryPath) {
commitDocument (entryPath, author) {
let self = this
let gitFilePath = entryPath + '.md'
let commitMsg = ''
@ -207,7 +207,7 @@ module.exports = {
commitMsg = (isTracked) ? 'Updated ' + gitFilePath : 'Added ' + gitFilePath
return self._git.add(gitFilePath)
}).then(() => {
return self._git.commit(commitMsg).catch((err) => {
return self._git.exec('commit', ['-m', commitMsg, '--author="' + author.name + ' <' + author.email + '>"']).catch((err) => {
if (_.includes(err.stdout, 'nothing to commit')) { return true }
})
})

libs/local.js → server/libs/local.js

libs/logger.js → server/libs/logger.js

libs/markdown.js → server/libs/markdown.js

libs/rights.js → server/libs/rights.js

libs/search-index/index.js → server/libs/search-index/index.js

libs/search-index/siUtil.js → server/libs/search-index/siUtil.js

libs/search.js → server/libs/search.js

@ -51,6 +51,10 @@ module.exports = {
add (content) {
let self = this
if (!content.isEntry) {
return Promise.resolve(true)
}
return self._isReady.then(() => {
return self.delete(content._id).then(() => {
return self._si.concurrentAddAsync({

libs/system.js → server/libs/system.js

libs/uploads-agent.js → server/libs/uploads-agent.js

libs/uploads.js → server/libs/uploads.js

libs/winston-transports/bugsnag.js → server/libs/winston-transports/bugsnag.js

libs/winston-transports/rollbar.js → server/libs/winston-transports/rollbar.js

libs/winston-transports/sentry.js → server/libs/winston-transports/sentry.js

locales/de/auth.json → server/locales/de/auth.json

locales/de/common.json → server/locales/de/common.json

locales/en/auth.json → server/locales/en/auth.json

locales/en/common.json → server/locales/en/common.json

locales/es/auth.json → server/locales/es/auth.json

locales/es/common.json → server/locales/es/common.json

locales/fr/auth.json → server/locales/fr/auth.json

locales/fr/common.json → server/locales/fr/common.json

locales/ko/auth.json → server/locales/ko/auth.json

locales/ko/common.json → server/locales/ko/common.json

locales/pt/auth.json → server/locales/pt/auth.json

locales/pt/common.json → server/locales/pt/common.json

locales/ru/auth.json → server/locales/ru/auth.json

locales/ru/common.json → server/locales/ru/common.json

middlewares/auth.js → server/middlewares/auth.js

middlewares/flash.js → server/middlewares/flash.js

middlewares/security.js → server/middlewares/security.js

middlewares/seo.js → server/middlewares/seo.js

models/bruteforce.js → server/models/bruteforce.js

models/entry.js → server/models/entry.js

models/upl-file.js → server/models/upl-file.js

models/upl-folder.js → server/models/upl-folder.js

models/user.js → server/models/user.js

views/auth/login.pug → server/views/auth/login.pug

views/common/alerts.pug → server/views/common/alerts.pug

views/common/footer.pug → server/views/common/footer.pug

views/common/header.pug → server/views/common/header.pug

views/common/mixins.pug → server/views/common/mixins.pug

views/configure/index.pug → server/views/configure/index.pug

views/error-forbidden.pug → server/views/error-forbidden.pug

views/error-notexist.pug → server/views/error-notexist.pug

views/error.pug → server/views/error.pug

views/layout.pug → server/views/layout.pug

views/modals/admin-createuser.pug → server/views/modals/admin-createuser.pug

views/modals/admin-deleteuser.pug → server/views/modals/admin-deleteuser.pug

views/modals/admin-upgrade.pug → server/views/modals/admin-upgrade.pug

views/modals/create-discard.pug → server/views/modals/create-discard.pug

views/modals/create.pug → server/views/modals/create.pug

views/modals/edit-discard.pug → server/views/modals/edit-discard.pug

views/modals/editor-codeblock.pug → server/views/modals/editor-codeblock.pug

views/modals/editor-file.pug → server/views/modals/editor-file.pug

views/modals/editor-image.pug → server/views/modals/editor-image.pug

views/modals/editor-link.pug → server/views/modals/editor-link.pug

views/modals/editor-video.pug → server/views/modals/editor-video.pug

views/modals/move.pug → server/views/modals/move.pug

views/pages/admin/_layout.pug → server/views/pages/admin/_layout.pug

views/pages/admin/profile.pug → server/views/pages/admin/profile.pug

views/pages/admin/settings.pug → server/views/pages/admin/settings.pug

views/pages/admin/stats.pug → server/views/pages/admin/stats.pug

views/pages/admin/users-edit.pug → server/views/pages/admin/users-edit.pug

views/pages/admin/users.pug → server/views/pages/admin/users.pug

views/pages/all.pug → server/views/pages/all.pug

views/pages/create.pug → server/views/pages/create.pug

views/pages/edit.pug → server/views/pages/edit.pug

views/pages/source.pug → server/views/pages/source.pug

views/pages/view.pug → server/views/pages/view.pug

views/pages/welcome.pug → server/views/pages/welcome.pug

2
test/lint.js

@ -71,7 +71,7 @@ describe('Code Linting', () => {
const lint = new PugLint()
const pugConfig = fs.readJsonSync('.pug-lintrc.json')
lint.configure(pugConfig)
let report = lint.checkPath('./views')
let report = lint.checkPath('./server/views')
expect(report).toPugLint()
})
})

2
wiki.js

@ -7,7 +7,7 @@
// Licensed under AGPLv3
// ===========================================
const init = require('./init')
const init = require('./server/init')
require('yargs') // eslint-disable-line no-unused-expressions
.usage('Usage: node $0 <cmd> [args]')

7368
yarn.lock
File diff suppressed because it is too large
View File

Loading…
Cancel
Save