1 | <h2 align="center">
|
2 | <img src="https://cotype.dev/logo.svg" alt="cotype" />
|
3 | </h2>
|
4 |
|
5 | <p align="center">
|
6 | <a href="https://circleci.com/gh/cotype/core/tree/master">
|
7 | <img src="https://circleci.com/gh/cotype/core/tree/master.svg?style=shield" alt="CircleCI">
|
8 | </a>
|
9 | <a href="https://www.npmjs.com/package/@cotype/core">
|
10 | <img src="https://img.shields.io/npm/v/@cotype/core.svg" alt="npm package">
|
11 | </a>
|
12 | <a href="https://codecov.io/gh/cotype/core/">
|
13 | <img src="https://img.shields.io/codecov/c/gh/cotype/core/master.svg" alt="Codecov">
|
14 | </a>
|
15 | <a href="https://github.com/semantic-release/semantic-release">
|
16 | <img src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg" alt="semantic-release">
|
17 | </a>
|
18 | <a href="https://greenkeeper.io/">
|
19 | <img src="https://badges.greenkeeper.io/cotype/core.svg" alt="Greenkeeper">
|
20 | </a>
|
21 | </p>
|
22 | <p> </p>
|
23 |
|
24 | Cotype manages structured content that can accessed via APIs.
|
25 | The system itself is not concerned with the actual rendering of the data - this is left completely to the consumer which could be a server that generates HTML, a client-rendered web app or a native app that reads the data via HTTP.
|
26 |
|
27 | ---
|
28 |
|
29 | > Cotype is not free software.
|
30 | > In order to run cotype on a public server you must purchase a valid license.
|
31 | > Please contact info@cellular.de for inquiries.
|
32 |
|
33 | ---
|
34 |
|
35 | ## Install
|
36 |
|
37 | `npm install @cotype/core`
|
38 |
|
39 | ## Usage
|
40 |
|
41 | ```ts
|
42 | // server.ts
|
43 | import { init, Opts /* ... */ } from "@cotype/core";
|
44 |
|
45 | const port = 1337;
|
46 | const opts: Opts = {
|
47 | /* ...see https://github.com/cotype/core#options */
|
48 | };
|
49 |
|
50 | /* Init cotype and receive express app */
|
51 | init(opts).then(({ app }) => {
|
52 | /* Make the app listen on a specific port
|
53 | * see https://nodejs.org/api/net.html#net_server_listen */
|
54 | app.listen(port, () =>
|
55 | console.log(`Cotype listening on http://localhost:${port}!`)
|
56 | );
|
57 | }, console.error);
|
58 | ```
|
59 |
|
60 | ## Options
|
61 |
|
62 | **\*required**
|
63 |
|
64 | - #### \*`models: ModelOpts[]`
|
65 |
|
66 | Describes what content types exist, which fields they have and how they are edited.
|
67 |
|
68 | - #### \*`persistenceAdapter: Promise<PersistenceAdapter>`
|
69 |
|
70 | Adapter providing the database connection of the server.
|
71 |
|
72 | Cotype provides a [Knex.js](https://knexjs.org/) adapter that can be configured
|
73 | with a [Knex configuration object](https://knexjs.org/#Installation-client).
|
74 |
|
75 | ```ts
|
76 | import { init, knexAdapter } from "@cotype/core";
|
77 |
|
78 | init({
|
79 | /* ... */
|
80 | persistenceAdapter: knexAdapter({
|
81 | /* see https://knexjs.org/#Installation-client */
|
82 | })
|
83 | });
|
84 | ```
|
85 |
|
86 | - #### \*`storage: Storage`
|
87 |
|
88 | When files are uploaded, the meta data is stored in the database while the
|
89 | binary data is stored using this adapter.
|
90 |
|
91 | Cotype comes with an adapter that stores all data on the local file system.
|
92 |
|
93 | ```ts
|
94 | import { init, FsStorage } from "@cotype/core";
|
95 |
|
96 | init({
|
97 | /* ... */
|
98 | storage: new FsStorage("./uploads")
|
99 | });
|
100 | ```
|
101 |
|
102 | - #### \*`thumbnailProvider: ThumbnailProvider`
|
103 |
|
104 | Thumbnail creator for uploaded image files.
|
105 | Cotype does not come with a default provider for size-reasons.
|
106 |
|
107 | Please see [`@cotype/local-thumbnail-provider`](https://github.com/cotype/local-thumbnail-provider) for a straight-forward implementation.
|
108 |
|
109 | * #### `basePath: string`
|
110 |
|
111 | **Default: `/`**
|
112 |
|
113 | Can be used to mount the app on a sub-path.
|
114 | For example `http://localhost:3000/cms`.
|
115 |
|
116 | ```ts
|
117 | import { init } from "@cotype/core";
|
118 |
|
119 | init({
|
120 | /* ... */
|
121 | basePath: "/cms"
|
122 | });
|
123 | ```
|
124 |
|
125 | - #### `sessionOpts: SessionOpts`
|
126 |
|
127 | The server uses a [cookie-session](https://github.com/expressjs/cookie-session)
|
128 | that holds nothing but the user's id.
|
129 |
|
130 | See [cookie-session#options](https://github.com/expressjs/cookie-session#options)
|
131 | for details.
|
132 |
|
133 | The cookie is signed to prevent any sort of tampering. Therefore a secret must
|
134 | be provided using `sessionOpts.secret` or via the `SESSION_SECRET` env var. If
|
135 | omitted, a random string will be generated, which means that sessions will
|
136 | become invalid once the server is restarted.
|
137 |
|
138 | ## How it works
|
139 |
|
140 | ### Content APIs
|
141 |
|
142 | The data can be accessed via REST. The server provides an interactive API explorer that developers can use to browse the content model.
|
143 |
|
144 | NOTE: THe content API is read-only. Modifying content is only possible via the management API that is used by the UI.
|
145 |
|
146 | ### Content Model
|
147 |
|
148 | The content model is defined using only primitives, so it can be serialized into JSON. It describes what content types exist, which fields they have and how they are edited.
|
149 |
|
150 | For a list of available content models check out the [typings file](typings/models.d.ts).
|
151 |
|
152 | Currently the content model is part of the server and changes require a re-deployment/restart in order to take effect. But since the model is plain JSON it would be pretty easy to manage content types directly in the CMS and store is alongside the data.
|
153 |
|
154 | ### Data Storage
|
155 |
|
156 | The data is stored in a Database. Built-In entities (like users, roles, etc.) live in a traditional relational model, whereas all content is stored as JSON in a common table. Content is immutable and each change creates a new revision. If the publish/draft system is enabled for a given content type, API clients won't see the changes until they are published (or a preview is requested).
|
157 |
|
158 | There are two materialized views (one for all published, one for the latest versions) that have indexes on the JSON data as well as a full-text index for searching.
|
159 |
|
160 | ## Contributing
|
161 |
|
162 | Pull-Requests, Issues, Feedback, Coffee and positive thoughts are very welcome!
|
163 |
|
164 | If you want to work on this project locally using the development environment
|
165 | or want to know more about what we consider "internal stuff", please refer
|
166 | to the [contribution guidelines](https://github.com/cotype/core/blob/master/CONTRIBUTING.md)
|
167 |
|
\ | No newline at end of file |