fix: setup https support + various fixes

This commit is contained in:
Nick 2019-03-16 22:41:48 -04:00
parent 7bbf683902
commit 358e79d7f5
7 changed files with 64 additions and 58 deletions

View File

@ -171,8 +171,8 @@
v-card.text-xs-center(flat) v-card.text-xs-center(flat)
template(v-if='loading') template(v-if='loading')
.mt-3(style='width: 64px; display:inline-block;') .mt-3(style='width: 64px; display:inline-block;')
atom-spinner( breeding-rhombus-spinner(
:animation-duration='800' :animation-duration='2000'
:size='64' :size='64'
color='#1976d2' color='#1976d2'
) )
@ -199,11 +199,11 @@
<script> <script>
import axios from 'axios' import axios from 'axios'
import _ from 'lodash' import _ from 'lodash'
import { AtomSpinner } from 'epic-spinners' import { BreedingRhombusSpinner } from 'epic-spinners'
export default { export default {
components: { components: {
AtomSpinner BreedingRhombusSpinner
}, },
props: { props: {
telemetryId: { telemetryId: {

View File

@ -83,18 +83,18 @@
v-list-tile-title.pl-3.caption {{tocSubItem.title}} v-list-tile-title.pl-3.caption {{tocSubItem.title}}
v-divider(inset, v-if='tocIdx < toc.length - 1') v-divider(inset, v-if='tocIdx < toc.length - 1')
v-divider v-divider
v-list.grey(dense, :class='darkMode ? `darken-3` : `lighten-4`') //- v-list.grey(dense, :class='darkMode ? `darken-3` : `lighten-4`')
v-subheader.pl-4.yellow--text.text--darken-4 Rating //- v-subheader.pl-4.yellow--text.text--darken-4 Rating
.text-xs-center //- .text-xs-center
v-rating( //- v-rating(
v-model='rating' //- v-model='rating'
color='yellow darken-3' //- color='yellow darken-3'
background-color='grey lighten-1' //- background-color='grey lighten-1'
half-increments //- half-increments
hover //- hover
) //- )
.pb-2.caption.grey--text 5 votes //- .pb-2.caption.grey--text 5 votes
v-divider //- v-divider
template(v-if='tags.length') template(v-if='tags.length')
v-list.grey(dense, :class='darkMode ? `darken-3-d3` : `lighten-3`') v-list.grey(dense, :class='darkMode ? `darken-3-d3` : `lighten-3`')
v-subheader.pl-4.teal--text Tags v-subheader.pl-4.teal--text Tags

View File

@ -130,7 +130,7 @@ module.exports = {
// JWT is NOT valid, set as guest // JWT is NOT valid, set as guest
if (!user) { if (!user) {
if (true || WIKI.auth.guest.cacheExpiration.isSameOrBefore(moment.utc())) { if (WIKI.auth.guest.cacheExpiration.isSameOrBefore(moment.utc())) {
WIKI.auth.guest = await WIKI.models.users.getGuestUser() WIKI.auth.guest = await WIKI.models.users.getGuestUser()
WIKI.auth.guest.cacheExpiration = moment.utc().add(1, 'm') WIKI.auth.guest.cacheExpiration = moment.utc().add(1, 'm')
} }
@ -176,9 +176,7 @@ module.exports = {
user.groups.forEach(grp => { user.groups.forEach(grp => {
const grpId = _.isObject(grp) ? _.get(grp, 'id', 0) : grp const grpId = _.isObject(grp) ? _.get(grp, 'id', 0) : grp
_.get(WIKI.auth.groups, `${grpId}.pageRules`, []).forEach(rule => { _.get(WIKI.auth.groups, `${grpId}.pageRules`, []).forEach(rule => {
console.info(page.path) switch (rule.match) {
console.info(rule)
switch(rule.match) {
case 'START': case 'START':
if (_.startsWith(`/${page.path}`, `/${rule.path}`)) { if (_.startsWith(`/${page.path}`, `/${rule.path}`)) {
checkState = this._applyPageRuleSpecificity({ rule, checkState, higherPriority: ['END', 'REGEX', 'EXACT'] }) checkState = this._applyPageRuleSpecificity({ rule, checkState, higherPriority: ['END', 'REGEX', 'EXACT'] })
@ -194,6 +192,7 @@ module.exports = {
if (reg.test(page.path)) { if (reg.test(page.path)) {
checkState = this._applyPageRuleSpecificity({ rule, checkState, higherPriority: ['EXACT'] }) checkState = this._applyPageRuleSpecificity({ rule, checkState, higherPriority: ['EXACT'] })
} }
break
case 'EXACT': case 'EXACT':
if (`/${page.path}` === `/${rule.path}`) { if (`/${page.path}` === `/${rule.path}`) {
checkState = this._applyPageRuleSpecificity({ rule, checkState, higherPriority: [] }) checkState = this._applyPageRuleSpecificity({ rule, checkState, higherPriority: [] })

View File

@ -60,7 +60,7 @@ module.exports = {
}, },
async register(obj, args, context) { async register(obj, args, context) {
try { try {
await WIKI.models.users.register({...args, verify: true }, context) await WIKI.models.users.register({ ...args, verify: true }, context)
return { return {
responseResult: graphHelper.generateSuccess('Registration success') responseResult: graphHelper.generateSuccess('Registration success')
} }

View File

@ -1,15 +0,0 @@
'use strict'
/**
* Flash middleware
*
* @param {Express Request} req Express Request object
* @param {Express Response} res Express Response object
* @param {Function} next Next callback function
* @return {any} void
*/
module.exports = (req, res, next) => {
res.locals.flash = req.flash('alert')
next()
}

View File

@ -1,7 +1,7 @@
'use strict'
const _ = require('lodash') const _ = require('lodash')
/* global WIKI */
/** /**
* SEO Middleware * SEO Middleware
* *

View File

@ -1,5 +1,18 @@
const path = require('path') const path = require('path')
const uuid = require('uuid/v4') const uuid = require('uuid/v4')
const bodyParser = require('body-parser')
const compression = require('compression')
const express = require('express')
const favicon = require('serve-favicon')
const http = require('http')
const https = require('https')
const Promise = require('bluebird')
const fs = require('fs-extra')
const _ = require('lodash')
const cfgHelper = require('./helpers/config')
const crypto = Promise.promisifyAll(require('crypto'))
const pem2jwk = require('pem-jwk').pem2jwk
const semver = require('semver')
/* global WIKI */ /* global WIKI */
@ -11,23 +24,6 @@ module.exports = () => {
WIKI.system = require('./core/system') WIKI.system = require('./core/system')
// ----------------------------------------
// Load modules
// ----------------------------------------
const bodyParser = require('body-parser')
const compression = require('compression')
const express = require('express')
const favicon = require('serve-favicon')
const http = require('http')
const Promise = require('bluebird')
const fs = require('fs-extra')
const _ = require('lodash')
const cfgHelper = require('./helpers/config')
const crypto = Promise.promisifyAll(require('crypto'))
const pem2jwk = require('pem-jwk').pem2jwk
const semver = require('semver')
// ---------------------------------------- // ----------------------------------------
// Define Express App // Define Express App
// ---------------------------------------- // ----------------------------------------
@ -138,8 +134,8 @@ module.exports = () => {
WIKI.telemetry.sendEvent('setup', 'install-start') WIKI.telemetry.sendEvent('setup', 'install-start')
// Basic checks // Basic checks
if (!semver.satisfies(process.version, '>=10.14')) { if (!semver.satisfies(process.version, '>=10.12')) {
throw new Error('Node.js 10.14.x or later required!') throw new Error('Node.js 10.12.x or later required!')
} }
// Upgrade from WIKI.js 1.x? // Upgrade from WIKI.js 1.x?
@ -356,7 +352,33 @@ module.exports = () => {
WIKI.logger.info(`HTTP Server on port: [ ${WIKI.config.port} ]`) WIKI.logger.info(`HTTP Server on port: [ ${WIKI.config.port} ]`)
app.set('port', WIKI.config.port) app.set('port', WIKI.config.port)
WIKI.server = http.createServer(app)
if (WIKI.config.ssl.enabled) {
WIKI.logger.info(`HTTPS Server on port: [ ${WIKI.config.port} ]`)
const tlsOpts = {}
try {
if (WIKI.config.ssl.format === 'pem') {
tlsOpts.key = fs.readFileSync(WIKI.config.ssl.key)
tlsOpts.cert = fs.readFileSync(WIKI.config.ssl.cert)
} else {
tlsOpts.pfx = fs.readFileSync(WIKI.config.ssl.pfx)
}
if (!_.isEmpty(WIKI.config.ssl.passphrase)) {
tlsOpts.passphrase = WIKI.config.ssl.passphrase
}
if (!_.isEmpty(WIKI.config.ssl.dhparam)) {
tlsOpts.dhparam = WIKI.config.ssl.dhparam
}
} catch (err) {
WIKI.logger.error('Failed to setup HTTPS server parameters:')
WIKI.logger.error(err)
return process.exit(1)
}
WIKI.server = https.createServer(tlsOpts, app)
} else {
WIKI.logger.info(`HTTP Server on port: [ ${WIKI.config.port} ]`)
WIKI.server = http.createServer(app)
}
WIKI.server.listen(WIKI.config.port, WIKI.config.bindIP) WIKI.server.listen(WIKI.config.port, WIKI.config.bindIP)
var openConnections = [] var openConnections = []