Adds a treecreeper api to an express app. It provides
- a GraphQL api
- RESTful CRUD endpoints
- Takes care of initialising a schema-sdk and api-db-manager, so that data structures automatically update
Returns an express instance with the GraphQL and REST apis set up according to the options provided
A treecreeper
object is attached to the express instance with the following properties
A reference to treecreeper's internal logger, which decorates each log with useful application/request metadata
A function that returns a boolean indicating whether the application is successfully keeping the schema that defines its data types up to date
See tc-api-rest-handlers
for details
An express app. If none is provided, one will be created
Options to pass to tc-schema-sdk
. Note that some options may be provided via environment variables
The path at which the treecreeper api is served
The path, relative to treecreeperPath, where the graphql api is served
Methods accepted by the graphql api
Array of middlewares to call before the graphql handler executes
The path, relative to treecreeperPath, where the REST api is served
Array of middlewares to call before the relevant REST handler executes
An [optional] reference to a tc-api-s3-document-store instance (or a library implementing the same API), used to store large properties outside the neo4j instance
See the tc-api-graphql README
See the tc-api-graphql README
See the tc-api-graphql README
A boolean indicating whether the application needs to republish the schema to somewhere once it has updated the graphqlApi. Note that republishing depends on a TREECREEPER_SCHEMA_BUCKET
envioronment variable, which should be the name of an s3 bucket.
If the application needs to republish the schema to somewhere once it has updated the graphqlApi, this string indicates the prefix to use
Optional integer to set maximum time DB will be queried for and, by association, maximum time a request can stay alive for before being rejected and erroring
const { getApp } = require('@financial-times/tc-api-rest-express');
const {
authorization,
rateLimiting,
disableWrites,
} = require('../middlewares');
const PORT = process.env.PORT || 8888;
getApp({
graphqlMethods: ['post', 'get'],
graphqlMiddlewares: [authorization, rateLimiting],
restMiddlewares: [authorization, rateLimiting, disableWrites],
}).then(app => {
app.listen(PORT, () => {
app.logger(`Listening on ${PORT}`);
});
});