Commit 23ce013d authored by Jure's avatar Jure

Merge branch 'authsome-dep' into 'master'

Update to async authsome

See merge request !12
parents a4da8983 3d14ed24
Pipeline #2567 passed with stage
in 3 minutes and 46 seconds
image: node:7 image: pubsweet/pubsweet-test-base
before_script: before_script:
- npm install -g yarn
- yarn - yarn
test: test:
script: script:
- npm test - xvfb-run --server-args "-screen 0 1024x768x24" npm test
coverage: '/^All files\s+\|\s+(\d+.\d+)\s\|.*$/' coverage: '/^All files\s+\|\s+(\d+.\d+)\s\|.*$/'
variables:
DEBUG: nightmare:*
lint: lint:
script: script:
......
import 'regenerator-runtime/runtime'
import React from 'react' import React from 'react'
import ReactDOM from 'react-dom' import ReactDOM from 'react-dom'
......
import React from 'react' import React from 'react'
import config from 'config' import PropTypes from 'prop-types'
import AuthenticatedComponent from 'pubsweet-client/src/components/AuthenticatedComponent' import AuthenticatedComponent from 'pubsweet-client/src/components/AuthenticatedComponent'
import Manage from 'pubsweet-component-manage/Manage' import Manage from 'pubsweet-component-manage/Manage'
import Navigation from '../Navigation/Navigation' import Navigation from '../Navigation/Navigation'
export default ({children, ...props}) => ( const AuthenticatedManage = ({children, ...props}) => (
<AuthenticatedComponent <Manage nav={<Navigation />}>
authsome={config.authsome} <AuthenticatedComponent
operation='create' operation='create'
selector={(state) => state.collections[0]} selector={(state) => state.collections[0]}
{...props} unauthorized={<p>You are not authorized to view this page.</p>}
> {...props}
<Manage nav={<Navigation />}> >
{children} {children}
</Manage> </AuthenticatedComponent>
</AuthenticatedComponent> </Manage>
) )
AuthenticatedManage.propTypes = {
children: PropTypes.node
}
export default AuthenticatedManage
...@@ -2,7 +2,8 @@ const path = require('path') ...@@ -2,7 +2,8 @@ const path = require('path')
module.exports = { module.exports = {
'pubsweet-server': { 'pubsweet-server': {
dbPath: path.join(__dirname, '..', 'api', 'db', 'test') dbPath: path.join(__dirname, '..', 'api', 'db', 'test'),
secret: 'test'
}, },
// prevent logging from swaming test output // prevent logging from swaming test output
logger: { logger: {
......
...@@ -10,9 +10,10 @@ ...@@ -10,9 +10,10 @@
], ],
"dependencies": { "dependencies": {
"@pubsweet/logger": "^0.0.1", "@pubsweet/logger": "^0.0.1",
"authsome": "0.0.9",
"jest": "^21.1.0", "jest": "^21.1.0",
"pubsweet": "1.0.0-alpha.5", "pubsweet": "1.0.0-alpha.6",
"pubsweet-client": "^1.0.0-beta.3", "pubsweet-client": "1.0.0-beta.6",
"pubsweet-component-blog": "^0.3.1", "pubsweet-component-blog": "^0.3.1",
"pubsweet-component-html": "^0.2.0", "pubsweet-component-html": "^0.2.0",
"pubsweet-component-login": "^0.5.1", "pubsweet-component-login": "^0.5.1",
...@@ -63,6 +64,7 @@ ...@@ -63,6 +64,7 @@
"node-sass": "^4.5.2", "node-sass": "^4.5.2",
"pouchdb-adapter-memory": "^6.1.1", "pouchdb-adapter-memory": "^6.1.1",
"react-hot-loader": "^3.0.0-beta.6", "react-hot-loader": "^3.0.0-beta.6",
"regenerator-runtime": "^0.11.0",
"sass-loader": "^6.0.3", "sass-loader": "^6.0.3",
"script-loader": "^0.7.0", "script-loader": "^0.7.0",
"standard": "^10.0.1", "standard": "^10.0.1",
...@@ -74,7 +76,7 @@ ...@@ -74,7 +76,7 @@
"webpack-hot-middleware": "^2.18.0" "webpack-hot-middleware": "^2.18.0"
}, },
"scripts": { "scripts": {
"lint": "eslint app test webpack", "lint": "eslint --ext js,jsx app test webpack",
"start": "pubsweet start", "start": "pubsweet start",
"setupdb": "pubsweet setupdb", "setupdb": "pubsweet setupdb",
"test": "jest" "test": "jest"
......
require('app-module-path').addPath(process.cwd())
const path = require('path')
if (!process.env.NODE_ENV) {
process.env.NODE_ENV = 'development'
}
const dotenvPath = path.join(process.cwd(), `.env.${process.env.NODE_ENV}`)
require('dotenv').config({ path: dotenvPath })
const config = require('config')
const http = require('http')
const express = require('express')
const webpack = require('webpack')
const pubsweet = require('pubsweet-server')
const logger = require('@pubsweet/logger')
const onError = (err) => logger.error(err)
const collect = (val, memo) => memo.push(val) && memo
let program
let server
let serverListening = false
const webpackconfig = require(path.join(
process.cwd(), 'webpack', `webpack.${process.env.NODE_ENV}.config.js`
))
const registerDevtools = (app, compiler, cb) => {
app.use(require(
path.join(process.cwd(), 'node_modules', 'webpack-dev-middleware')
)(compiler, {
noInfo: true,
stats: {
colors: true,
chunks: false
},
publicPath: '/assets/'
}))
app.use(
require(
path.join(process.cwd(), 'node_modules', 'webpack-hot-middleware')
)(compiler)
)
cb()
}
const registerComponents = app => {
config.pubsweet.components.forEach(name => {
const component = require(path.join(process.cwd(), 'node_modules', name))
logger.info('Registered component', name)
// Backwards compatibility, old name was 'backend', new name is 'server'
let serverComponent = component.server || component.backend
if (serverComponent) {
serverComponent()(app)
logger.info('Registered server component', name)
}
})
}
let watcher
const startWatcher = () => {
const chokidar = require('chokidar')
// TODO: use a whitelist instead of a blacklist
watcher = chokidar.watch(process.cwd(), {
ignored: /(node_modules|_build|api\/db|.git|logs|static|webpack|pubsweet.log|app|uploads|.idea)/
})
let update = (msg, reload) => {
logger.info(`Detected filesystem change: ${msg}`)
if (reload) reloadServer()
}
watcher.on('ready', () => {
logger.info('Watching for filesystem changes')
watcher
.on('add', path => update(`File ${path} added`, true))
.on('change', path => update(`File ${path} changed`, true))
.on('unlink', path => update(`File ${path} removed`, true))
.on('addDir', path => update(`Directory ${path} added`, true))
.on('unlinkDir', path => update(`Directory ${path} removed`, true))
.on('error', onError)
})
program.watch.forEach(watcher.add)
}
const compiler = webpack(webpackconfig)
const runapp = (err, stats, cb) => {
if (err) onError(err)
const rawapp = express()
// rawapp.get('*.js', function (req, res, next) {
// if (/\.js$|\.css$|\.html$/.test(req.url)) {
// req.url = req.url + '.gz'
// res.set('Content-Encoding', 'gzip')
// }
// next()
// })
const postcompile = (err, stats) => {
if (err) {
logger.error('Webpack compilation failed:', err)
process.exit(1)
} else if (stats) {
logger.info('Webpack compilation completed:', stats.toString({
hash: false,
chunks: false,
assets: false
}))
}
registerComponents(rawapp)
logger.info(`Registered components`)
const app = pubsweet(rawapp)
logger.info(`Setup app`)
const port = process.env.PORT || 3000
app.set('port', port)
logger.info(`Using port ${port}`)
server = http.createServer(app)
logger.info(`Created HTTP server`)
const onListening = () => {
// logger.info(`PubSweet is listening on port ${server.address().port}`)
logger.info(`PubSweet is listening on port ${port}`)
serverListening = true
if (cb) cb(server) // used to enable testing
if (process.env.NODE_ENV === 'development' && !watcher) startWatcher()
}
server.on('error', onError)
server.on('listening', onListening)
server.listen(port)
}
if (process.env.NODE_ENV === 'development') {
registerDevtools(rawapp, compiler, postcompile)
} else {
compiler.run(postcompile)
}
}
const reloadServer = () => {
if (serverListening) {
logger.info('Restarting app')
serverListening = false
server.close(runapp)
} else {
server.on('listening', () => {
setTimeout(() => server.close(reloadServer), 100)
})
}
}
if (require.main === module) {
// file is being executed
// console.log('start.js FILE IS BEING EXECUTED')
program = require('commander')
program
.option('--watch [path]', 'Watch path for changes', collect, [])
.parse(process.argv)
runapp()
} else {
// file is being required - used to enable testing
// console.log('start.js FILE IS BEING REQUIRED')
module.exports = cb => runapp(null, null, cb)
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment