Netlify

Deploy to Netlify with sensible defaults. Easily use Netlify Functions, Netlify Redirects, and Netlify Headers.

.
├── functions/
├── layouts/
│   ├── index.headers
│   └── index.redirects
└── netlify.toml

See also the Hugo Docs: Host on Netlify.

Functions

See: Functions

Redirects

./layouts/index.redirects is converted on build to ./public/_redirects.

{{- range $p := .Site.Pages -}}
{{- range .Aliases }}
{{ . }} {{ $p.RelPermalink -}}
{{- end }}
{{- end -}}

See also the Netlify docs: Redirects and rewrites

Headers

./layouts/index.headers is converted on build to ./public/_headers.

/*
  Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
  X-Content-Type-Options: nosniff
  X-XSS-Protection: 1; mode=block
  Content-Security-Policy: default-src 'self'; manifest-src 'self'; connect-src 'self'; font-src 'self'; img-src 'self' data:; script-src 'self' 'nonce-dXNlcj0iaGVsbG8iLGRvbWFpbj0iaGVua3ZlcmxpbmRlLmNvbSIsZG9jdW1lbnQud3JpdGUodXNlcisiQCIrZG9tYWluKTs=' 'sha256-aWZ3y/RxbBYKHXH0z8+8ljrHG1mSBvyzSfxSMjBSaXk='; style-src 'self'
  X-Frame-Options: SAMEORIGIN
  Referrer-Policy: strict-origin
  Feature-Policy: geolocation 'self'
  Cache-Control: public, max-age=31536000
  Access-Control-Allow-Origin: *

See also the Netlify docs: Custom headers

Configuration

./netlify.toml:

[build]
  publish = "public"
  functions = "functions"

[build.environment]
  NODE_VERSION = "16.13.1"
  NPM_VERSION = "8.1.2"

[context.production]
  command = "npm run build"

[context.deploy-preview]
  command = "npm run build -- -b $DEPLOY_PRIME_URL"

[context.branch-deploy]
  command = "npm run build -- -b $DEPLOY_PRIME_URL"

[context.next]
  command = "npm run build"

[context.next.environment]
  HUGO_ENV = "next"

[dev]
  framework = "#custom"
  command = "npm run start"
  targetPort = 1313
  port = 8888
  publish = "public"
  autoLaunch = false

See also the Netlify docs: File-based configuration

Edit this page on GitHub