How to use the @storefront-api/lib/module.StorefrontApiModule function in @storefront-api/lib

To help you get started, we’ve selected a few @storefront-api/lib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DivanteLtd / storefront-api / src / modules / sample-api / index.ts View on Github external
import { StorefrontApiModule, registerExtensions } from '@storefront-api/lib/module'
import { StorefrontApiContext } from '@storefront-api/lib/module/types'
import { Router } from 'express';
import order from './api/order';
import user from './api/user';
import stock from './api/stock';
import cart from './api/cart';
import catalog from './api/catalog'
import img from './api/img'
import { version } from '../../../package.json';
import path from 'path'

export const SampleApiModule: StorefrontApiModule = new StorefrontApiModule({
  key: 'sample-api',

  initApi: ({ config, db, app }: StorefrontApiContext): void => {
    let api = Router();

    // mount the order resource
    api.use('/order', order({ config, db }));

    // mount the user resource
    api.use('/user', user({ config, db }));

    // mount the stock resource
    api.use('/stock', stock({ config, db }));

    // mount the cart resource
    api.use('/cart', cart({ config, db }));