presta
presta copied to clipboard
Minimalist serverless framework for SSR, SSG, serverless APIs and more.
Presta
Minimalist serverless framework for SSR, SSG, serverless APIs and more.
Usage
In each file, define a route:
export const route = '/products/:sku'
Or generate an array of static paths:
export async function getStaticPaths() {
return ['/products/book']
}
Or both, as a fallback for static files that aren't matched.
export const route = '/products/:sku'
export async function getStaticPaths() {
return ['/products/book']
}
Handlers are just... serverless handlers.
export async function handler(event, context) {}
Return a string to render HTML:
export async function handler(event, context) {
return `<h1>Hello world!</h1>`
}
Or a normal serverless response object:
export async function handler(event, context) {
return {
statusCode: 200,
headers: {
'Content-Type': 'text/html',
},
body: `<h1>Hello world!</h1>`,
}
}
For convenience, you can use a few shortcuts that automatically set
Content-Type
headers, including html
, json
, and xml
:
export async function handler(event, context) {
return {
html: `<h1>Hello world!</h1>`,
}
}
Config
Peep the CLI with npx presta -h
for more info. You can also define a config
file with any CLI options predefined:
export const files = ['index.tsx', 'pages/*.jsx']
export const output = 'build'
export const assets = 'public'
Deployment
Presta builds everything to config.output
.
- static paths and assets to
<config.output>/static
- serverless functions to
<config.output>/functions
Ecosystem
- @presta/html — util for creating HTML pages
- @presta/adapter-netlify — deployment adapter for Netlify
- @presta/source-filesystem — source and watch local files
Contributing
We'd love your help getting Presta to v1.0.0
. Have a look at the contributing doc or say hello in a new Issue. Also please review our code of conduct.
License
MIT License © Sure Thing