npm i
- Create file .env with:
SESSION_SECRET=<secret>
, where<secret>
is an unguessable secret string
- Make sure you have MongoDB running
npm run dev
- Open
localhost:8080
in the browser
auto-py-to-exe
"id": , "text": , "count": ,
"name": "check", "check": false, "isset": false
"name": "lights", "lights": [ { "name": "salon", "work": true }, { "name": "kuchnia", "work": false }, { "name": "sypialnia", "work": false }, { "name": "łazienka", "work": true } ]
- Create file
backend/routes/my-endpoint.ts
:
import { z } from "zod";
import { makePostEndpoint } from "./route";
export function myEndpoint(/* pass objects like database here */) {
return {
post: makePostEndpoint({
schema: z.object({
// example begin
name: z.string(),
id: z.number(),
// example end
}),
async handle({ /* params from schema */ }, { login, email }) {
// DO STUFF HERE
// return value is sent to the client as JSON
},
});
};
}
- Add this to
backend/routes/index.ts
:
export * from "./my-endpoint";
- Add this to
app.ts
inside theaddApi
call:
"my-endpoint": routes.myEndpoint(/* pass objects like database here */),
- Use the endpoint in frontend code:
import * as typedApi from "../util/typed-api";
// in an async function
const json = await typedApi.post("my-endpoint", {
// example begin
name: "Volper",
id: 1,
// example end
});