The route
A route is a function: Hodi calls it, it answers. This one reads the Greeting setting and sends it back.
What you do- Open
server/index.ts: it's the part of your plugin that runs on the server. - 2On the highlighted line, add an exclamation mark after
greeting, in the text the route sends back. - 3Click Say hello in the preview: your route answers Hi!.
1{2 "id": "hello-world",3 "name": "Hello world",4 "version": "0.1.0",5 "api": 2,6 "settings": [7 {8 "key": "greeting",9 "type": "text",10 "default": "Hi"11 }12 ]13}1import type { ServerPlugin } from '@hodi-app/plugin-sdk/server'23const plugin: ServerPlugin = {4 routes: {5 'POST /hello': async (_request, ctx) => {6 const { greeting } = ctx.settings()7 return { body: { text: `${greeting}` } }8 }9 }10}1112export default pluginPreviewLive
Hello world
Your first plugin.
GreetingHi
Say helloYour route's answer