How to use netlify-redirect-parser - 4 common examples

To help you get started, we’ve selected a few netlify-redirect-parser 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 netlify / build / packages / netlify-plugin-no-more-404 / parseRules.js View on Github external
function parseRules(projectDir) {
  let rules = []

  const baseRedirectsPath = path.resolve(projectDir, '_redirects')
  if (fs.existsSync(baseRedirectsPath)) {
    rules = rules.concat(
      parseFile(redirectParser.parseRedirectsFormat, '_redirects', fs.readFileSync(baseRedirectsPath, 'utf-8')),
    )
  }

  // const baseTOMLPath = path.resolve(projectDir, 'netlify.toml')
  // if (fs.existsSync(baseTOMLPath)) {
  //   rules = rules.concat(
  //     parseFile(redirectParser.parseTomlFormat, 'base netlify.toml', fs.readFileSync(baseTOMLPath, 'utf-8'))
  //   )
  // }
  return rules
}
github netlify / cli / src / utils / rules-proxy.js View on Github external
function parseRules(projectDir, publicDir) {
  const rules = []

  const generatedRedirectsPath = path.resolve(publicDir, '_redirects')
  if (fs.existsSync(generatedRedirectsPath)) {
    rules.push(...
      parseFile(redirectParser.parseRedirectsFormat, '_redirects', fs.readFileSync(generatedRedirectsPath, 'utf-8'))
    )
  }

  const baseRedirectsPath = path.resolve(projectDir, '_redirects')
  if (fs.existsSync(baseRedirectsPath)) {
    rules.push(...
      parseFile(redirectParser.parseRedirectsFormat, '_redirects', fs.readFileSync(baseRedirectsPath, 'utf-8'))
    )
  }

  const generatedTOMLPath = path.resolve(projectDir, 'netlify.toml')
  if (fs.existsSync(generatedTOMLPath)) {
    rules.push(...
      parseFile(redirectParser.parseTomlFormat, 'generated netlify.toml', fs.readFileSync(generatedTOMLPath, 'utf-8'))
    )
  }
github netlify / cli / src / utils / rules-proxy.js View on Github external
rules.push(...
      parseFile(redirectParser.parseRedirectsFormat, '_redirects', fs.readFileSync(generatedRedirectsPath, 'utf-8'))
    )
  }

  const baseRedirectsPath = path.resolve(projectDir, '_redirects')
  if (fs.existsSync(baseRedirectsPath)) {
    rules.push(...
      parseFile(redirectParser.parseRedirectsFormat, '_redirects', fs.readFileSync(baseRedirectsPath, 'utf-8'))
    )
  }

  const generatedTOMLPath = path.resolve(projectDir, 'netlify.toml')
  if (fs.existsSync(generatedTOMLPath)) {
    rules.push(...
      parseFile(redirectParser.parseTomlFormat, 'generated netlify.toml', fs.readFileSync(generatedTOMLPath, 'utf-8'))
    )
  }

  const baseTOMLPath = path.resolve(projectDir, 'netlify.toml')
  if (fs.existsSync(baseTOMLPath)) {
    rules.push(...
      parseFile(redirectParser.parseTomlFormat, 'base netlify.toml', fs.readFileSync(baseTOMLPath, 'utf-8'))
    )
  }

  const generatedYAMLPath = path.resolve(projectDir, 'netlify.yml')
  if (fs.existsSync(generatedYAMLPath)) {
    rules.push(...
      parseFile(redirectParser.parseYamlFormat, 'generated netlify.yml', fs.readFileSync(generatedYAMLPath, 'utf-8'))
    )
  }
github netlify / cli / src / utils / rules-proxy.js View on Github external
rules.push(...
      parseFile(redirectParser.parseTomlFormat, 'generated netlify.toml', fs.readFileSync(generatedTOMLPath, 'utf-8'))
    )
  }

  const baseTOMLPath = path.resolve(projectDir, 'netlify.toml')
  if (fs.existsSync(baseTOMLPath)) {
    rules.push(...
      parseFile(redirectParser.parseTomlFormat, 'base netlify.toml', fs.readFileSync(baseTOMLPath, 'utf-8'))
    )
  }

  const generatedYAMLPath = path.resolve(projectDir, 'netlify.yml')
  if (fs.existsSync(generatedYAMLPath)) {
    rules.push(...
      parseFile(redirectParser.parseYamlFormat, 'generated netlify.yml', fs.readFileSync(generatedYAMLPath, 'utf-8'))
    )
  }

  const baseYAMLPath = path.resolve(projectDir, 'netlify.yml')
  if (fs.existsSync(baseYAMLPath)) {
    rules.push(...
      parseFile(redirectParser.parseYamlFormat, 'base netlify.yml', fs.readFileSync(baseYAMLPath, 'utf-8'))
    )
  }

  return rules
}

netlify-redirect-parser

Parses netlify redirects into a js object representation

MIT
Latest version published 2 months ago

Package Health Score

92 / 100
Full package analysis