Skip to content

astro

Config imports API Reference

Astro

Config imports API Reference

Config imports API Reference

This virtual module astro:config exposes a non-exhaustive, serializable, type-safe version of the Astro configuration. There are two submodules for accessing different subsets of your configuration values: /client and /server.

All available config values can be accessed from astro:config/server. However, for code executed on the client, only those values exposed by astro:config/client will be available. This protects your information by only making some data available to the client.

Imports from astro:config/client

The following helpers are imported from the client directory of the virtual config module.

Use this submodule for client-side code:


function addForwardSlash(path) {
  if (trailingSlash === "always") {
    return path.endsWith("/") ? path : path + "/"
  } else {
    return path
  }
}

See more about the configuration imports available from astro:config/client:

Imports from astro:config/server

The following helpers are imported from the server directory of the virtual config module.

These imports include everything available from astro:config/client as well as additional sensitive information about your file system configuration that is not safe to expose to the client.

Use this submodule for server side code:





        // generate data from some operation
        let data = JSON.stringify([]);
        writeFileSync(fileURLToPath(file), data, "utf-8");
      }
    }
  }
}

See more about the configuration imports available from astro:config/server:

Imports from astro/config

The following helpers are imported from the regular config module:

defineConfig()

Type: (config: AstroUserConfig) => AstroUserConfig

Configures your project with type safety in a supported Astro configuration file.

envField

Type: object

Describes the supported data types when defining environment variables.

Each data type must define the variable type with context ("client" or "server") and access ("secret" or "public"). In addition, you can define a default value, specify whether the variable is optional (default false), and some data types provide optional validation methods.

Learn more about using type safe environment variables in your Astro project.

envField.string()

Type: (options: StringFieldInput) => StringField

Defines an environment variable of string type. You can perform string validation with Zod using the following properties: max, min, length, url, includes, startsWith, and endsWith.

The following example defines the expected shape for an environment variable storing an API URL:

Learn more about configuring a no-op passthrough service.

sessionDrivers

Type: object

Describes the built-in driver used for session storage.

The following example configures the Redis driver to enable sessions:


export default defineConfig({
  session: {
    driver: sessionDrivers.redis({
      url: process.env.REDIS_URL
    }),
  }
})

Learn more about using sessions in your Astro project.

sharpImageService()

Type: (config?: SharpImageServiceConfig) => ImageServiceConfig

Retrieves the Sharp service used to process Astro’s image assets. This takes an optional object describing the configuration options for Sharp.

validateConfig()

See validateConfig() in the Programmatic API reference.