Minimalist web framework for serverless APIs, SSR/SSG pages and more. Less than 1500 lines of TypeScript, small install size, powered by esbuild. Get started right now with no setup: npx presta dev index.js

Usage


In each file, export a dynamic route:

// index.js
export const route = '/:slug?'

Or generate an array of static paths to render:

// index.js
export async function getStaticPaths() {
  return [ '/', '/about' ]
}

Or both. Unmatched files will be rendered dynamically:

// index.js
export const route = '/:slug?'

export async function getStaticPaths() {
  return [ '/', '/about' ]
}

What's left is just a normal serverless function:

// index.js
export const route = '/:slug?'

export async function getStaticPaths() {
  return [ '/', '/about' ]
}

export async function handler(event, context) {
  return {
    statusCode: 200,
    headers: {
      'Content-Type': 'text/html'
    },
    body: '<h1>Hello world!</h1>'
  }
}

Presta handlers have a few shortcuts. Like, you can return a string to render HTML by default.

// index.js
export async function handler(event, context) {
  return '<h1>Hello world!</h1>'
}

Or use a shorthand in order to pass other properties and automatically set headers:

// index.js
export async function handler(event, context) {
  return {
    statusCode: 404,
    html: '<h1>404 Not Found</h1>'
  }
}

Other shorthands include json and xml. When using json, Presta will automatically stringify the response.

// index.js
export async function handler(event, context) {
  return {
    json: {
      count: 1,
      products: [
        { sku: '1234abcd' }
      ]
    }
  }
}

Config


Peep the CLI with npx presta -h for more info. You can also define a config file with any CLI options predefined:

// presta.config.js
export const files = ['index.tsx', 'pages/*.jsx']
export const output = 'build'
export const assets = 'public'

Deployment


Presta builds everything to config.output (or --output):

Static paths and assets to (config.output)/static

Serverless functions to (config.output)/functions

Ecosystem


Check out the other packages in the Presta ecosystem:

And check out the Github for more information, to file and issue, or contribute.