Preview Tutorial
In the case of Node.js
, the UI to open the preview screen must be provided by the user.
Here is a guide to an example preview setup, assuming React is used for the front end.
Node.JS
const SEACRET_KEY = "SEACRET_KEY";
const payload = { subject: "Cool Subject", body: "# Headline\n This is a **Markdown** text\n ", to: [ ] };
const getDraft = async (request) => { const apiKey = request.headers.get("API-KEY"); if(apiKey !== SEACRET_KEY){ return new Response("error") } const url = new URL(request.url); const contentId = url.pathname.substring(url.pathname.lastIndexOf('/') + 1) const draft = /// Retrieve data from the database using contentId. return new Response(JSON.stringify(draft))}
- First, open the Preview tab in Vell, press
Add New
and selectCustom
. - Select the added items, and in
Headers
, add a header whose key isAPI-KEY
and whose value is the aboveSEACRET_KEY
. InEndpoint
, enter the endpoint for processing the abovegetDraft
. - The Node.js side is accessed from Vell with the following URL to retrieve data.Enter thehttps://your-service.com/<contentId>
https://your-service.com
part in theEndpoint
field.
React
const PREVIEW_ID = /// Preview ID copied from Vell
const contents = [ { id: "123", subject: "Cool Subject"}, { id: "456", subject: "Good Subject"}, { id: "789", subject: "Super Subject"},]
export default function Contents() { return contents.map((content) => { return <a href={`https://vell-letter.com/preview/${content.id}?previewId=${PREVIEW_ID}`}> <div> {content.subject} </div> </a> })}
- Open the Preview tab in Vell and select the item to configure
Node.js
. - Copy the value of
Preview ID
and set it toPREVIEW_ID
above. - When the content link is opened, the Vell preview screen opens, accesses the Node.js side, acquires the data, and displays it on the screen.