You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
909 B
40 lines
909 B
import { Directus } from '@directus/sdk';
|
|
|
|
/**
|
|
* Abstract Class for handling Directus Api
|
|
*
|
|
* @author Björn Hase <me@herr-hase.wtf>
|
|
* @license http://opensource.org/licenses/MIT The MIT License
|
|
* @link https://gitea.node001.net/HerrHase/super-fastify-directus.git
|
|
*
|
|
*/
|
|
|
|
class DirectusAbstractStore {
|
|
|
|
/**
|
|
*
|
|
*
|
|
*
|
|
* @param {string} endpoint
|
|
*
|
|
*/
|
|
constructor(endpoint) {
|
|
this.endpoint = endpoint
|
|
|
|
this.directus = new Directus(process.env.DIRECTUS_API_URL, {
|
|
auth: {
|
|
staticToken: process.env.DIRECTUS_API_TOKEN
|
|
}
|
|
})
|
|
|
|
// if endpoint not set throw Error
|
|
if (!this.endpoint) {
|
|
throw new Error('Endpoint in ' + this.constructor.name + ' missing!')
|
|
}
|
|
|
|
// create items
|
|
this.items = this.directus.items(this.endpoint)
|
|
}
|
|
}
|
|
|
|
export default DirectusAbstractStore |