{"id":27070305,"url":"https://github.com/worksofliam/node-fastify-typescript-fullstack","last_synced_at":"2025-04-05T22:35:00.383Z","repository":{"id":283006831,"uuid":"950378608","full_name":"worksofliam/node-fastify-typescript-fullstack","owner":"worksofliam","description":"Node.js template for a fullstack app","archived":false,"fork":false,"pushed_at":"2025-03-18T04:21:19.000Z","size":47,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-18T05:25:59.154Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/worksofliam.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-18T04:20:35.000Z","updated_at":"2025-03-18T04:23:14.000Z","dependencies_parsed_at":"2025-03-18T23:46:50.377Z","dependency_job_id":null,"html_url":"https://github.com/worksofliam/node-fastify-typescript-fullstack","commit_stats":null,"previous_names":["worksofliam/node-fastify-typescript-fullstack"],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worksofliam%2Fnode-fastify-typescript-fullstack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worksofliam%2Fnode-fastify-typescript-fullstack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worksofliam%2Fnode-fastify-typescript-fullstack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/worksofliam%2Fnode-fastify-typescript-fullstack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/worksofliam","download_url":"https://codeload.github.com/worksofliam/node-fastify-typescript-fullstack/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247411266,"owners_count":20934650,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-05T22:34:59.973Z","updated_at":"2025-04-05T22:35:00.376Z","avatar_url":"https://github.com/worksofliam.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node.js, Fastify, TypeScript, OpenAPI, fullstack template\n\nThis is a fullstack template for Node.js, Fastify, TypeScript, OpenAPI, and more. It includes a backend scaffold with Fastify, TypeScript, and OpenAPI, as well as a frontend API client scaffold. There is no frontend UI. You can add that and make use of the generated client.\n\n## Setup\n\n1. Clone this template\n2. `cd backend \u0026\u0026 npm install` for the backend\n3. `cd ui \u0026\u0026 npm install` for the frontend API client\n4. `cd spec \u0026\u0026 npm run build` to generate the client and backend types\n\n### Test backend\n\n1. `cd backend`\n2. `npm run dev` to start the backend server\n\nOr, debug from VS Code with `Launch Program (backend)`.\n\n* Head to `localhost:8080/data` and see the request fail due to missing JWT token.\n* Use the `/login` API with `admin:admin` to get a JWT token.\n\n### Adding additional routes\n\nAlways start by adding the route to the OpenAPI spec in `spec/openapi.yaml`. Then, run `npm run build` in the `spec` directory to generate the updated client and backend types. \n\nEnsure your new route has a simple `operationId`, like `getData` or `setData`, as this is what the handler function will be named in the `backend/src/web/routes/handlers.ts`.\n\n## More ideas 🚀\n\n* Add a backend database client like Db2 for i, Postgres, or SQLite\n* Add a frontend UI with React, Vue, or Svelte\n* Add an improved login system in `doLogin` with a more secure authentication method\n\n### React Router tips for the frontend\n\nMake a router with `react-router-dom` v6+ and use the `loader` property to handle the authentication and redirect to the login page if needed.\n\n\u003cdetails\u003e\n\n\u003csummary\u003eExample\u003c/summary\u003e\n\n```ts\nconst router = createBrowserRouter([\n  {\n    loader: HomeLoader,\n    errorElement: \u003cErrorPage /\u003e,\n    path: \"dash\",\n    children: [\n      {\n        index: true,\n        element: \u003cHome /\u003e,\n      },\n    ]\n  },\n    {\n    index: true,\n    element: \u003cLogin /\u003e,\n    errorElement: \u003cErrorPage /\u003e,\n  },\n]);\n```\n\n```ts\nexport async function HomeLoader() {\n  // https://stackoverflow.com/questions/44133536/\n  const token = localStorage.getItem(`jwt`);\n\n  // console.log(`token: ${token}`)\n\n  if (!token) {\n    return redirect(`/`);\n  }\n\n  OpenAPI.TOKEN = token;\n\n  try {\n    // TODO: implement this service to verify the token\n    const res = await DefaultService.getCurrentUser();\n    console.log(res);\n    useUserStore.subscribe((state) =\u003e {\n      state.login(res.username, token);\n    });\n\n    return {}\n  } catch (e) {\n    useUserStore.subscribe((state) =\u003e {\n      state.logout();\n    });\n\n    OpenAPI.TOKEN = undefined;\n    localStorage.removeItem(`jwt`);\n\n    return redirect(`/`);\n  }\n}\n```\n\n\u003c/details\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworksofliam%2Fnode-fastify-typescript-fullstack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fworksofliam%2Fnode-fastify-typescript-fullstack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworksofliam%2Fnode-fastify-typescript-fullstack/lists"}