UNPKG

822 BJavaScriptView Raw
1'use strict'
2
3const { resolve } = require('path')
4
5const { parseAllHeaders } = require('netlify-headers-parser')
6
7const { warnHeadersParsing, warnHeadersCaseSensitivity } = require('./log/messages')
8
9// Retrieve path to `_headers` file (even if it does not exist yet)
10const getHeadersPath = function ({ build: { publish } }) {
11 return resolve(publish, HEADERS_FILENAME)
12}
13
14const HEADERS_FILENAME = '_headers'
15
16// Add `config.headers`
17const addHeaders = async function ({ headers: configHeaders, ...config }, headersPath, logs) {
18 const { headers, errors } = await parseAllHeaders({
19 headersFiles: [headersPath],
20 configHeaders,
21 minimal: true,
22 })
23 warnHeadersParsing(logs, errors)
24 warnHeadersCaseSensitivity(logs, headers)
25 return { ...config, headers }
26}
27
28module.exports = { getHeadersPath, addHeaders }