DPDK Architecture  ->  Bootstrap (v3.0.5)

Functions
>= v1.21.0

Below is a list of all available functions after constructing a new NextBootstrap()

bootstrap.addMiddleware(middleware)           // Adds an Express.JS Middleware
bootstrap.addGraphQLField(field)              // Adds a custom GraphQL Compose Field

bootstrap.get(route, callback)                // Adds a custom Express.JS HTTP GET route
bootstrap.post(route, callback)               // Adds a custom Express.JS HTTP POST route
bootstrap.put(route, callback)                // Adds a custom Express.JS HTTP PUT route
bootstrap.patch(route, callback)              // Adds a custom Express.JS HTTP PATCH route
bootstrap.delete(route, callback)             // Adds a custom Express.JS HTTP DELETE route

bootstrap.init(completed)                     // Initializes the bootstrap
bootstrap.exit()                              // Clean exits the bootstrap

Examples

Below are some examples based on the functions above:

Custom GraphQL Compose Field
>= v1.4.25

This example creates a new GraphQL field called example with the type String and will return the result: Hello World! when queried through GraphQL

bootstrap.addGraphQLField({
  example: {
    name: 'example',
    type: 'String',
    resolve: async () => {
      return 'Hello World!';
    }
  }
});

Additional GraphQL Compose Documentation: https://graphql-compose.github.io/docs/api/Resolver.html

Custom Express.JS Middleware
>= v1.0.1

This example creates a middleware that logs incoming every request

bootstrap.addMiddleware(function (req, res, next) {
  console.log(`[${req.method}] ${req.originalUrl}`);
  next();
});

Additional Express.JS Documentation: https://expressjs.com/en/4x/api.html#app.use

Custom Express.JS HTTP GET route
>= v1.21.0

This example creates the /test route that will respond with Hello World!

bootstrap.get('/test', function (req, res) {
  res.send('Hello World!');
});

Additional Express.JS Documentation: https://expressjs.com/en/4x/api.html#app.get.method

Custom Express.JS HTTP POST route
>= v1.21.0

This example creates the /test route that will respond with OK and is able to read the body that was send as JSON

bootstrap.post('/test', function (req, res) {
  console.log(req.body);
  res.send('OK');
});

Additional Express.JS Documentation: https://expressjs.com/en/4x/api.html#app.post.method

Last modifiedFriday, April 30, 2021, 12:00:21 PM UTC
Last authorColin van Eenige
Commit ID4c7a701