ReactStaticREADME.md4 matches
2930Custom middleware can be added in an array as the second argument.
31Middleware can add data to the `req.data` object or return a response for things like API endpoints.
3233```tsx
55```tsx
56// example middleware
57async function api (req: Request, res: Response, next): Promise<Response> {
58if (req.pathname !== "/api") return next();
59if (req.method === "POST") {
60return Repsonse.json({ message: "Hello POST request" });
63}
6465export default render(App, [ api ]);
66```
67
ReactStream_migratedmain.tsx7 matches
34const useMiddleware = Array.isArray(opts); // for backwards compat
35const options: ReactStreamOptions = !Array.isArray(opts) ? opts : {};
36const { api, getInitialProps } = options;
3738if (typeof document !== "undefined" && module) {
48// DEPRECATED (for backwards compat)
49options.robots && robots(options.robots),
50options.api && deprecatedCustomAPI(options.api),
51options.getInitialProps && deprecatedGetInitiaProps(options.getInitialProps),
52// New custom middleware
127// DEPRECATED
128// DEPRECATE (for backwards compat)
129const deprecatedCustomAPI = (api?: RequestHandler): Middleware => async (req, res, next) => {
130if (!api) return next();
131if (req.method === "GET") return next();
132return api(req);
133};
134const deprecatedGetInitiaProps = (getProps: DataFetcher<any>): Middleware => async (req, res, next) => {
142/** DEPRECATED: Optional text response for robots.txt */
143robots?: string;
144/** DEPRECATED: Optional API request handler for all non-GET methods */
145api?: RequestHandler;
146/** DEPRECATED: data fetcher to set initial props based on request */
147getInitialProps?: DataFetcher<any>;
myBookmarkManagermain.tsx11 matches
181// ----------------- Data Loading -----------------
182async function fetchSavedBookmarks() {
183const response = await fetch("/api/bookmarks");
184const data = await response.json();
185setAllSavedBookmarks(data);
232e.preventDefault();
233if (editBookmarkId === null) {
234const response = await fetch("/api/bookmarks", {
235method: "POST",
236headers: { "Content-Type": "application/json" },
251}
252} else {
253const response = await fetch(`/api/bookmarks/${editBookmarkId}`, {
254method: "PUT",
255headers: { "Content-Type": "application/json" },
274// ----------------- Export / Import -----------------
275async function saveAllBookmarks() {
276const response = await fetch("/api/bookmarks/export");
277const bookmarkData = await response.text(); // Get as text instead of blob
278const blob = new Blob([bookmarkData], { type: "application/json" });
297try {
298const loadedBookmarks = JSON.parse(fileContent);
299const response = await fetch("/api/bookmarks/import", {
300method: "POST",
301headers: { "Content-Type": "application/json" },
1294<title>My Bookmark Manager</title>
1295<link
1296href="https://fonts.googleapis.com/css2?family=Quicksand:wght@300;400;500;600;700&display=swap"
1297rel="stylesheet"
1298/>
1342});
13431344app.get("/api/bookmarks", async (c) => {
1345const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
1346await sqlite.execute(`
1363});
13641365app.post("/api/bookmarks", async (c) => {
1366const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
1367const {
1394});
13951396app.put("/api/bookmarks/:id", async (c) => {
1397const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
1398const id = c.req.param("id");
1473});
14741475app.get("/api/bookmarks/export", async (c) => {
1476const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
1477const bookmarks = await sqlite.execute(`
1488});
14891490app.post("/api/bookmarks/import", async (c) => {
1491const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
1492const importedBookmarks = await c.req.json();
falDemoAppmain.tsx2 matches
15try {
16const fal = createFalClient({
17proxyUrl: "/api/fal/proxy",
18});
19139}
140141if (url.pathname === "/api/fal/proxy") {
142return falProxyRequest(req);
143}
twitterAlertREADME.md4 matches
31Refer to [Twitter's search operators](https://socialdata.gitbook.io/docs/twitter-tweets/retrieve-search-results-by-keyword#endpoint-parameters) to fine-tune your query.
3233### 4. Test API call
34Set `isProd = false` in the code if you are testing, to ensure there are enough tweets to display. <br>
35Toggle it back to `true` when you're ready to run this cron job in production and actuall send notifications.
6061### NOTE: Usage Limits
62This val uses the SocialData API for Twitter data:
6364- **Proxies via Val Town's [SocialDataProxy](https://www.val.town/v/stevekrouse/socialDataProxy)**: Limited to 10 cents per day for [**Val Town Pro users**](https://www.val.town/pricing). This API is *only* for Pro users.
65- **Need more calls?** Sign up for your own [SocialData API token](https://socialdata.tools) and configure the [`socialDataSearch`](https://www.val.town/v/stevekrouse/socialDataSearch) function.
cerebras_coderREADME.md2 matches
671. Sign up for [Cerebras](https://cloud.cerebras.ai/)
82. Get a Cerebras API Key
93. Save it in a [Val Town environment variable](https://www.val.town/settings/environment-variables) called `CEREBRAS_API_KEY`
1011# Todos
cerebras_codermain.tsx5 matches
212} catch (error) {
213Toastify({
214text: "We may have hit our Cerebras Usage limits. Try again later or fork this and use your own API key.",
215position: "center",
216duration: 3000,
1024};
1025} else {
1026const client = new Cerebras({ apiKey: Deno.env.get("CEREBRAS_API_KEY") });
1027const completion = await client.chat.completions.create({
1028messages: [
1149<meta name="viewport" content="width=device-width, initial-scale=1.0">
1150<title>CerebrasCoder</title>
1151<link rel="preconnect" href="https://fonts.googleapis.com" />
1152<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
1153<link
1154href="https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,300;0,400;0,500;1,300;1,400;1,500&family=DM+Sans:ital,opsz,wght@0,9..40,100..1000;1,9..40,100..1000&display=swap"
1155rel="stylesheet"
1156/>
1165<meta property="og:description" content="Turn your ideas into fully functional apps in less than a second – powered by Llama3.3-70b on Cerebras's super-fast wafer chips. Code is 100% open-source, hosted on Val Town."">
1166<meta property="og:type" content="website">
1167<meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">
1168
1169
twitterSearchmain.tsx1 match
14}): Promise<TweetResult[]> {
15const res = await twitterJSON({
16url: `https://api.twitter.com/2/tweets/search/recent?query=${await searchParams(
17{
18query,
cerebras_coderREADME.md2 matches
671. Sign up for [Cerebras](https://cloud.cerebras.ai/)
82. Get a Cerebras API Key
93. Save it in a [Val Town environment variable](https://www.val.town/settings/environment-variables) called `CEREBRAS_API_KEY`
1011# Todos
cerebras_codermain.tsx5 matches
212} catch (error) {
213Toastify({
214text: "We may have hit our Cerebras Usage limits. Try again later or fork this and use your own API key.",
215position: "center",
216duration: 3000,
1024};
1025} else {
1026const client = new Cerebras({ apiKey: Deno.env.get("CEREBRAS_API_KEY") });
1027const completion = await client.chat.completions.create({
1028messages: [
1149<meta name="viewport" content="width=device-width, initial-scale=1.0">
1150<title>CerebrasCoder</title>
1151<link rel="preconnect" href="https://fonts.googleapis.com" />
1152<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
1153<link
1154href="https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,300;0,400;0,500;1,300;1,400;1,500&family=DM+Sans:ital,opsz,wght@0,9..40,100..1000;1,9..40,100..1000&display=swap"
1155rel="stylesheet"
1156/>
1165<meta property="og:description" content="Turn your ideas into fully functional apps in less than a second – powered by Llama3.3-70b on Cerebras's super-fast wafer chips. Code is 100% open-source, hosted on Val Town."">
1166<meta property="og:type" content="website">
1167<meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">
1168
1169