Class AxonCore

Constructors

Methods

  • You can set one or many middlewares in global scope with this method.

    Parameters

    Returns Promise<void>

    core.globalMiddleware(authMiddleware)
    core.globalMiddleware([uploadMiddleware, useMiddleware])
  • Start listening to http incoming requests

    Parameters

    • host: string = "127.0.0.1"

      server host address

    • port: number | {
          http: number;
          https: number;
      } = 8000

      server port

    • Optionalcallback: ((mode?: string) => void)

      callback a function to run after starting to listen

        • (mode?): void
        • Parameters

          • Optionalmode: string

          Returns void

    Returns Promise<void>

    core.listen("0.0.0.0", 80)
    // or
    core.listen("0.0.0.0", {
    https: 443,
    http: 80
    })
  • A method to config core as you want

    If you want to config the core, use this method before all other methods.

    Parameters

    Returns Promise<void>

    core.loadConfig({
    DEBUG: true,
    CORS: {}
    });
  • Loads a specified Axon plugin using the plugin loader.

    Parameters

    • plugin: AxonPlugin

      The plugin to be loaded. It should be an instance of AxonPlugin.

    Returns Promise<void>

    // this class must implements AxonPlugin type
    class MyPlugin implements AxonPlugin {
    name = "plugin"
    version = "1.0.0"

    init(core) {}
    }

    core.loadPlugin(new MyPlugin())
  • loads created routes

    Parameters

    • router: AxonRouter

      instance of Router which routes setted with it.

    • Optionalprefix: string

    Returns Promise<void>

    const router = Router()

    router.get('/', async (req, res) => {});

    core.loadRoute(router) // without prefix
    core.loadRoute(router, '/api/v1') // with prefix