Apext Logo

APEXT

Config file

You can configure Apext to work with your own config file. The config file is a simple Javascript file.

To override the default config file, create a file called apext.config.js in the root of your project. It should export an object as follows:

module.exports = {}

The config file is merged with the default config file, so you can override any of the default settings.

Options

  • typescript - [boolean] Set to true to create Typescript files by default.
  • tsContent - [function] Takes a name and returns a template literal with the content of the Typescript file.
  • jsContent - [function] Takes a name and returns a template literal with the content of the Javascript file.

Default config file

module.exports = {
  typescript: false,
  tsContent: (name: string): string => `
    import type { NextApiRequest, NextApiResponse } from 'next'
    
    // @methods [GET,POST,PUT,DELETE]
    
    export default async function ${name}(
      req: NextApiRequest,
      res: NextApiResponse
    ) {
      switch (req.method) {
        case 'GET':
        case 'POST':
        case 'PUT':
        case 'DELETE':
        default:
          res.setHeader('Allow', [
            'GET',
            'POST',
            'PUT',
            'DELETE',
        ])
          return res.status(405).end(\`Method \${req.method} Not Allowed\`)
      }
    }
    `,
  jsContent: (name: string): string => `
    // @methods [GET,POST,PUT,DELETE]

    export default async function ${name}(req,res) {

    switch (req.method) {
        case 'GET':
        case 'POST':
        case 'PUT':
        case 'DELETE':
        default:
        res.setHeader('Allow', [
            'GET',
            'POST',
            'PUT',
            'DELETE',
        ])
        return res.status(405).end(\`Method \${req.method} Not Allowed\`)
      }
    }
    `,
}

An open source project powered by LifeSpikes

MIT Licensed - 2022