Web app
Serverless API endpoints
NREC
FUSEKI
NREC
KIBANA
ES
SANITY
token
token
(at build time)
import type { VercelRequest, VercelResponse } from '@vercel/node';
export default (request: VercelRequest, response: VercelResponse) => {
const { name } = request.query;
response.status(200).send(`Hello ${name}!`);
};
/api/[name].ts
Supports: Javascript, Go, Python, Ruby.
Node.js or Edge environment
Example: pure Node API application
export default async function handler(req, res) {
const { query: { esIndex, id }, method } = req
switch (method) {
case 'POST':
if (req.query.token !== process.env.ES_INDEX_SECRET) {
return res.status(401).send('You are not authorized!')
}
try {
const url = `${API_URL}/items/${id}?as=rdf`
const response = await fetch(url)
if (response.status === 404) {
return res.status(404).json({ message: "ID not found" })
}
// Deal with response
if (response.status >= 200 && response.status <= 299) {
const result = await response.json()
// Frame response with label_no props instead of standard JSON-LD language objects
const awaitFramed = jsonld.frame(result, {
'@context': [`${API_URL}/ns/es/context.json`],
'@type': 'HumanMadeObject',
'@embed': '@always',
})
let framed = await awaitFramed
framed.id = `${API_URL}/items/${framed.identifier}`
// We assume none lang tags is no
framed = JSON.parse(JSON.stringify(framed).replaceAll('_none":', '_no":'))
const esResponse = await client.index({ index: esIndex, id: framed.identifier, document: framed }, function (err) {
if (err) { throw Error(err)}
})
return res.status(200).json(esResponse)
} else {
console.log(response.status, response.statusText);
throw Error(response.statusText)
}
} catch (err) {
(err) => { return res.status(200).json({ message: err }) }
}
break
default:
res.setHeader('Allow', ['POST'])
res.status(405).end(`Method ${method} Not Allowed`)
}
}
POST /search/[esIndex]/[id].js
Example from api-ub.vercel.app (Next.js)
All you need if...
I'll come to when Vercel is not enough ;-)
We are going to ...
Max 45 minute build time
6000 deployments per day
Unlimited functions (unlimited API endpoints)
60 seconds execution time (serverless)
30 seconds execution time (edge)
Max 10 team members
60 Vercel projects per git repo (monorepo)
1 TB bandwidth
400 hours build time
More complicated limitations see the link
https://vercel.com/docs/concepts/limits/overview
No deployment from start to finish usually take more than fifteen minutes!
All the preview and test urls you could ever want!
Tests (almost) not necessary!
What, what??!?!
Ok, if static generating, at least. No broken build goes to production
Can build strong APIs given good underlying services