Ghost/ghost/members-ssr/README.md

83 lines
1.9 KiB
Markdown
Raw Normal View History

2019-04-02 11:20:43 +03:00
# Members Ssr
## Install
`npm install members-ssr --save`
or
`yarn add members-ssr`
## Usage
2019-04-05 09:46:54 +03:00
```js
const MembersSSR = require('./');
const {
exchangeTokenForSession,
2019-04-11 17:29:34 +03:00
getMemberDataFromSession,
deleteSession
2019-04-05 09:46:54 +03:00
} = MembersSSR({
cookieMaxAge: 1000 * 60 * 60 * 24 * 184, // 184 days max cookie age (default)
cookieSecure: true, // Secure cookie (default)
cookieName: 'members-ssr', // Name of cookie (default)
cookiePath: '/', // Path of cookie (default)
cookieKeys: 'some-coole-secret', // Key to sign cookie with
getMembersApi: () => membersApiInstance // Used to fetch data and verify tokens
2019-04-05 09:46:54 +03:00
});
2019-04-11 17:29:34 +03:00
const handleError = res => err => {
res.writeHead(err.statusCode);
res.end(err.message);
};
2019-04-05 09:46:54 +03:00
require('http').createServer((req, res) => {
if (req.method.toLowerCase() === 'post') {
exchangeTokenForSession(req, res).then((member) => {
2019-04-05 09:46:54 +03:00
res.writeHead(200);
res.end(JSON.stringify(member));
2019-04-11 17:29:34 +03:00
}).catch(handleError(res));
} else if (req.method.toLowerCase() === 'delete') {
deleteSession(req, res).then(() => {
res.writeHead(204);
res.end();
}).catch(handleError(res));
2019-04-05 09:46:54 +03:00
} else {
getMemberDataFromSession(req, res).then((member) => {
res.writeHead(200, {
'Content-Type': 'application/json'
});
res.end(JSON.stringify(member));
2019-04-11 17:29:34 +03:00
}).catch(handleError(res));
2019-04-05 09:46:54 +03:00
}
}).listen(3665);
```
2019-04-02 11:20:43 +03:00
## Develop
This is a mono repository, managed with [lerna](https://lernajs.io/).
Follow the instructions for the top-level repo.
1. `git clone` this repo & `cd` into it as usual
2. Run `yarn` to install top-level dependencies.
## Run
- `yarn dev`
## Test
- `yarn lint` run just eslint
- `yarn test` run lint and tests
# Copyright & License
2022-01-06 13:09:25 +03:00
Copyright (c) 2013-2022 Ghost Foundation - Released under the [MIT license](LICENSE).