Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cokoapps/server
  • jgutix/server
2 results
Show changes
Commits on Source (3)
......@@ -2,6 +2,13 @@
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
## [0.1.0](https://gitlab.coko.foundation/cokoapps/server/compare/v0.0.2...v0.1.0) (2020-04-04)
### Features
* **server:** cors config to allow client running on a different port ([dff70dd](https://gitlab.coko.foundation/cokoapps/server/commit/dff70dd2623adc3855129f1e98ba1cda68f37a0d))
### [0.0.2](https://gitlab.coko.foundation/cokoapps/server/compare/v0.0.1...v0.0.2) (2020-03-28)
......
# server
This package extends pubsweet's server with a few extra features, so that it can be used by coko-developed apps.
It is also meant to bundle as many server-side pubsweet dependencies as possible into one package, ensuring that the versions of those dependencies will play nice with each other.
## Get started
Install package and remove the dependencies it is meant to replace.
```sh
yarn remove pubsweet pubsweet-server # if migrating from an existing project
yarn add @coko/server
```
Add a central server file to your app.
```js
// server/app.js
// This is the express app your app will use
const { app } = require('@coko/server')
// You can modify the app or ensure other things are imported here
module.exports = app
```
If you place this file in `server/app.js`, starting the server should work automatically. If you wish to have a custom location for this file, you can declare that in your config.
```js
// config/default.js
{
'pubsweet-server': {
// replace helpers/customApp.js with your file's location
app: path.resolve(__dirname, 'helpers', 'customApp.js'),
}
}
```
### Cron support
All you need for cron-based scheduled tasks to run is to provide the path to your cron jobs.
```js
// config/default.js
{
'pubsweet-server': {
// replace server/services/cron with your folder's or file's location
cron: {
path: path.join(__dirname, '..', 'server', 'services', 'cron'),
},
}
}
```
A simple cronjob could look like this:
```js
const { cron } = require('@coko/server')
// Log this every second
cron.schedule('* * * * * *', () => {
console.log('this is the simplest thing')
})
```
The library that enables this is `node-cron`. Be sure to check its [documentation](https://github.com/node-cron/node-cron#node-cron) for further details.
### CORS support for the client
If you run your client on a different host/port than the server, you might run into issues where cross-origin requests are rejected. If that happens, make sure the following entries exist in your config. The server should take care of it once these are defined.
```js
// replace values with the ones you are using
{
'pubsweet-client': {
host: 'http://localhost',
port: 4000,
}
}
```
### Other exports from included packages
- `createJWT` is an export of a function in `pubsweet-server` that does just that. Useful if you have custom login resolvers.
### Future features
- Graphql middleware
- Include more pubsweet packages into the bundle
{
"name": "@coko/server",
"version": "0.0.2",
"version": "0.1.0",
"description": "A tweaked version of pubsweet-server for use by Coko's projects",
"main": "src/index.js",
"scripts": {
......@@ -30,6 +30,7 @@
"body-parser": "^1.19.0",
"config": "^3.3.1",
"cookie-parser": "^1.4.5",
"cors": "^2.8.5",
"express": "^4.17.1",
"helmet": "^3.22.0",
"http-status-codes": "^1.4.0",
......
......@@ -4,6 +4,7 @@ const path = require('path')
const bodyParser = require('body-parser')
const config = require('config')
const cors = require('cors')
const cookieParser = require('cookie-parser')
const express = require('express')
const helmet = require('helmet')
......@@ -55,6 +56,16 @@ const configureApp = app => {
)
}
// Allow CORS from client if host / port is different
app.use(
cors({
origin: `${config.get('pubsweet-client.host')}:${config.get(
'pubsweet-client.port',
)}`,
credentials: true,
}),
)
// Register passport authentication strategies
app.use(passport.initialize())
const authentication = require('pubsweet-server/src/authentication')
......
This diff is collapsed.