Some examples of how to use

This commit is contained in:
Tanya Byrne
2020-08-24 14:04:09 +01:00
parent c96d24eafe
commit fb10e32c9f
5 changed files with 10 additions and 0 deletions

View File

@@ -32,6 +32,7 @@ router.get(
'/:pk',
useCollection('directus_activity'),
sanitizeQuery,
cacheMiddleware,
asyncHandler(async (req, res) => {
const service = new ActivityService({ accountability: req.accountability });
const record = await service.readByKey(req.params.pk, req.sanitizedQuery);

View File

@@ -1,6 +1,7 @@
import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import sanitizeQuery from '../middleware/sanitize-query';
import cacheMiddleware from '../middleware/cache';
import CollectionsService from '../services/collections';
import useCollection from '../middleware/use-collection';
import MetaService from '../services/meta';
@@ -23,6 +24,7 @@ router.post(
router.get(
'/',
useCollection('directus_collections'),
cacheMiddleware,
asyncHandler(async (req, res) => {
const collectionsService = new CollectionsService({ accountability: req.accountability });
const metaService = new MetaService({ accountability: req.accountability });
@@ -38,6 +40,7 @@ router.get(
'/:collection',
useCollection('directus_collections'),
sanitizeQuery,
cacheMiddleware,
asyncHandler(async (req, res) => {
const collectionsService = new CollectionsService({ accountability: req.accountability });
const collectionKey = req.params.collection.includes(',')

View File

@@ -1,5 +1,6 @@
import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import cacheMiddleware from '../middleware/cache';
import * as ExtensionsService from '../services/extensions';
import { RouteNotFoundException } from '../exceptions';
@@ -7,6 +8,7 @@ const router = Router();
router.get(
'/:type',
cacheMiddleware,
asyncHandler(async (req, res) => {
const typeAllowList = ['interfaces', 'layouts', 'displays', 'modules'];

View File

@@ -2,6 +2,7 @@ import { Router } from 'express';
import asyncHandler from 'express-async-handler';
import FieldsService from '../services/fields';
import validateCollection from '../middleware/collection-exists';
import cacheMiddleware from '../middleware/cache';
import { schemaInspector } from '../database';
import { FieldNotFoundException, InvalidPayloadException } from '../exceptions';
import Joi from 'joi';
@@ -20,6 +21,7 @@ const router = Router();
router.get(
'/',
useCollection('directus_fields'),
cacheMiddleware,
asyncHandler(async (req, res) => {
const service = new FieldsService({ accountability: req.accountability });
@@ -32,6 +34,7 @@ router.get(
'/:collection',
validateCollection,
useCollection('directus_fields'),
cacheMiddleware,
asyncHandler(async (req, res) => {
const service = new FieldsService({ accountability: req.accountability });

View File

@@ -20,6 +20,7 @@ const cacheMiddleware: RequestHandler = asyncHandler(async (req, res, next) => {
// make the key of the cache the URL
// need to check that this will work for all endpoints
// node cache service
// have used query as then can decide whather to use cache or not from api call
if (!req.query.TTL) return next();
if (!req.query.dTTL) return next();