ReactStreamREADME.md4 matches
3637Custom middleware can be added in an array as the third argument.
38Middleware can add data to the `req.data` object or return a response for things like API endpoints.
3940```tsx
62```tsx
63// example middleware
64async function api (req: Request, res: Response, next): Promise<Response> {
65if (req.pathname !== "/api") return next();
66if (req.method === "POST") {
67return Repsonse.json({ message: "Hello POST request" });
70}
7172export default render(App, import.meta.url, [ api ]);
73```
74
ReactStreammain.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>;
endpointCalculatormain.tsx1 match
1/**
2* This program creates a basic calculator endpoint that accepts and returns data in the specified format.
3* It uses a RESTful API approach where the operation is specified in the URL path.
4* The numbers to operate on are passed as query parameters.
5* The result is returned as JSON.
4async function fetchRandomJoke() {
5const response = await fetch(
6"https://official-joke-api.appspot.com/random_joke",
7);
8return response.json();
hungryWhiteLeoponmain.tsx10 matches
1/**
2* This application helps users write detailed reviews of coffee shops. It fetches coffee shop data
3* from the OpenStreetMap Nominatim API, allows users to add custom details, and stores the augmented
4* information in a SQLite database. The app provides a user interface to view, add, and edit coffee shop reviews.
5*
6* It uses React for the frontend, the Nominatim API for initial coffee shop data,
7* and Val Town's SQLite for data persistence.
8*/
30const fetchCoffeeShops = async () => {
31try {
32const response = await fetch(`/api/coffee-shops?search=${encodeURIComponent(searchTerm)}`);
33if (!response.ok) throw new Error("Failed to fetch coffee shops");
34const data = await response.json();
41const fetchReviews = async () => {
42try {
43const response = await fetch("/api/reviews");
44if (!response.ok) throw new Error("Failed to fetch reviews");
45const data = await response.json();
6061try {
62const response = await fetch("/api/reviews", {
63method: "POST",
64headers: { "Content-Type": "application/json" },
192console.log("Table checked/created successfully");
193194if (url.pathname === "/api/coffee-shops") {
195const searchTerm = url.searchParams.get("search") || "";
196// Fetch coffee shops from OpenStreetMap Nominatim API
197const nominatimUrl = `https://nominatim.openstreetmap.org/search?q=coffee+${
198encodeURIComponent(searchTerm)
204});
205if (!nominatimResponse.ok) {
206throw new Error(`Nominatim API error! status: ${nominatimResponse.status}`);
207}
208const nominatimData = await nominatimResponse.json();
209if (!Array.isArray(nominatimData)) {
210throw new Error("Invalid data received from Nominatim API");
211}
212const coffeeShops = nominatimData.map((shop: any) => ({
221}
222223if (url.pathname === "/api/reviews") {
224if (request.method === "GET") {
225const reviews = await sqlite.execute(`SELECT * FROM ${KEY}_coffee_reviews_${SCHEMA_VERSION}`);
63</div>
64<a href={import.meta.url.replace("esm.town", "val.town")} target="_blank" rel="noopener noreferrer" className="view-source">View Source</a>
65<pre className="api-examples">
66{`// Axios example
67const axios = require('axios');
214text-decoration: underline;
215}
216.api-examples {
217margin-top: 20px;
218background-color: #f0f0f0;
3* It uses React for the UI, leverages emoji and Unicode symbols for a visually rich experience, and
4* incorporates Tailwind CSS for elegant, grayscale styling.
5* The wizard allows users to select tools, libraries, and APIs, then displays them in a shareable format.
6*/
7143{ name: "Discord", icon: "🗣️" },
144{ name: "Mattermost", icon: "📡" },
145{ name: "Zapier", icon: "🔗" },
146{ name: "IFTTT", icon: "🔄" },
147{ name: "Home Assistant", icon: "🏠" },
techstackinventorymain.tsx2 matches
29{Object.entries(techCategories).map(([category, technologies]) => (
30<div key={category} className="mb-6">
31<h2 className="text-xl font-semibold mb-2 text-gray-700 capitalize">{category}</h2>
32<div className="flex flex-wrap gap-2">
33{technologies.map(tech => (
52{Object.entries(selectedTech).map(([category, tech]) => (
53<li key={category} className="text-gray-700">
54<span className="font-medium capitalize">{category}:</span> {tech}
55</li>
56))}
sqliteExplorerAppmain.tsx2 matches
27<head>
28<title>SQLite Explorer</title>
29<link rel="preconnect" href="https://fonts.googleapis.com" />
3031<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
32<link
33href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@300..700&family=Source+Sans+3:ital,wght@0,200..900;1,200..900&display=swap"
34rel="stylesheet"
35/>
sqliteExplorerAppREADME.md1 match
13## Authentication
1415Login to your SQLite Explorer with [password authentication](https://www.val.town/v/pomdtr/password_auth) with your [Val Town API Token](https://www.val.town/settings/api) as the password.
1617## Todos / Plans