Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add preferStatic type to config #443

Merged
merged 3 commits into from
Nov 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 37 additions & 5 deletions src/function/v2.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,45 @@
export type { Context } from '@netlify/serverless-functions-api'

type Path = `/${string}`

type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS'

type CronSchedule = string

export interface Config {
path?: Path | Path[]
interface BaseConfig {
/**
* Configures the function to serve any static files that match the request
* URL and render the function only if no matching files exist.
*/
preferStatic?: boolean

/**
* Limits the HTTP methods for which the function will run. If not set, the
* function will run for all supported methods.
*/
method?: HTTPMethod | HTTPMethod[]
schedule?: CronSchedule
}

interface ConfigWithPath extends BaseConfig {
/**
* One or more URL paths for which the function will run. Paths must begin
* with a forward slash.
*
* {@link} https://ntl.fyi/func-routing
*/
path?: Path | Path[]

schedule?: never
}

interface ConfigWithSchedule extends BaseConfig {
path?: never

/**
* Cron expression representing the schedule at which the function will be
* automatically invoked.
*
* {@link} https://ntl.fyi/sched-func
*/
schedule: CronSchedule
}

export type Config = ConfigWithPath | ConfigWithSchedule