{"id":18885956,"url":"https://github.com/meldiron/appwrite-ssr-next-js","last_synced_at":"2025-04-14T22:15:47.254Z","repository":{"id":159198528,"uuid":"628698195","full_name":"Meldiron/appwrite-ssr-next-js","owner":"Meldiron","description":"Appwrite Loves Next.js! Demo application with authorized server-side and client-side rendering.","archived":false,"fork":false,"pushed_at":"2023-05-11T12:55:44.000Z","size":2503,"stargazers_count":20,"open_issues_count":2,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-14T22:15:37.055Z","etag":null,"topics":["appwrite","nextjs"],"latest_commit_sha":null,"homepage":"https://next-js.ssr.almostapps.eu/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Meldiron.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2023-04-16T18:43:08.000Z","updated_at":"2024-05-03T14:47:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"f8421b54-75b1-428e-a52c-0bc3a7bad313","html_url":"https://github.com/Meldiron/appwrite-ssr-next-js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meldiron%2Fappwrite-ssr-next-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meldiron%2Fappwrite-ssr-next-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meldiron%2Fappwrite-ssr-next-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meldiron%2Fappwrite-ssr-next-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Meldiron","download_url":"https://codeload.github.com/Meldiron/appwrite-ssr-next-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248968917,"owners_count":21191162,"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":["appwrite","nextjs"],"created_at":"2024-11-08T07:23:24.789Z","updated_at":"2025-04-14T22:15:47.237Z","avatar_url":"https://github.com/Meldiron.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Almost Cover](public/cover.png)\n\n# Almost SSR - Next.js\n\n\u003e Demo application with authorized server-side and client-side rendering.\n\n## 👀 Looking for Different Framework?\n\n* [🔦 Svelte Kit](https://github.com/Meldiron/appwrite-ssr-svelte-kit) | [svelte-kit.ssr.almostapps.eu](https://svelte-kit.ssr.almostapps.eu/)\n* [🔦 Nuxt](https://github.com/Meldiron/appwrite-ssr-nuxt) | [nuxt.ssr.almostapps.eu](https://nuxt.ssr.almostapps.eu/)\n* [🔦 Astro](https://github.com/Meldiron/appwrite-ssr-astro) | [astro.ssr.almostapps.eu](https://astro.ssr.almostapps.eu/)\n* [🔦 Qwik](https://github.com/Meldiron/appwrite-ssr-qwik) | [qwik.ssr.almostapps.eu](https://qwik.ssr.almostapps.eu/)\n* [🔦 Remix](https://github.com/Meldiron/appwrite-ssr-remix) | [remix.ssr.almostapps.eu](https://remix.ssr.almostapps.eu/)\n\n## 💭 So How Does It Work?\n\nAppwrite uses 1st party secure cookies for authorization. For legacy reasons, there are two such cookies. They are both very similar, but one's name ends with `_legacy` and is configured a tiny bit differently. It's also possible to use a fallback cookie, but that is not secure for production, and we will not be using that.\n\nTo ensure server-side rendering works, we need to set those cookies on our SSR server hostname instead of the Appwrite hostname. Let's say our Appwrite instance is on `cloud.appwrite.io`, and our app is on `myapp.com`. SSR server on domain `myapp.com` won't receive `appwrite.io` cookies. This is expected behavior, as browsers keep 1st party cookies securely scoped to specific domains.\n\nTo set those cookies on the SSR server, we need a special API endpoint in our SSR server. This endpoint will send a request to create a session, proxying email/password or other credentials. This endpoint next parses the response `set-cookie` header, replaces domain configuration on the cookies, and set's it's own `set-cookie` on the response to the client.\n\nWhen a client calls this endpoint, the cookie will now be set on the SSR server hostname instead of the Appwrite hostname.\n\nThis makes server-side rendering work, but now client-side rendering is broken. Since `set-cookie` coming to the browser only includes a cookie for the SSR server, talking to the Appwrite server directly won't have a proper cookie - there is no auth cookie on the Appwrite hostname. To overcome this problem, we ensure the Appwrite hostname is a subdomain of the SSR hostname. For example, if our SSR server runs on `myapp.com`, Appwrite needs a custom domain configured on `appwrite.myapp.com`. With this setup, all requests to the Appwrite server will include auth cookies, and the user will be properly authorized. This is possible thanks to Appwrite prefixing the cookie domain with `.`, meaning all subdomains can also access the cookie.\n\n## 🧰 Tech Stack\n\n- [Appwrite](https://appwrite.io/)\n- [Next.js](https://nextjs.org/)\n- [Pink Design](https://pink.appwrite.io/)\n- [TypeScript](https://www.typescriptlang.org/)\n\n## 🛠️ Setup Server\n\n1. Setup Appwrite server\n2. Create project `almostSsr`\n\n## 👀 Setup Client\n\n1. Install libarries `npm install`\n2. Update `AppwriteEndpoint` in `src/app/AppwriteService.ts`\n3. Start server `npm run dev`\n\n## 🚀 Deployment\n\n1. Deploy the frontend on your production domain. For example, `myapp.com`.\n2. Add the frontend domain as a trusted platform in your Appwrite project.\n3. Add a custom domain to your Appwrite project, which is a subdomain of your frontend. For example, `appwrite.myapp.com`.\n4. Update `SsrHostname` and `AppwriteHostname` in `src/app/AppwriteService.ts` with proper domains.\n\n## 🤝 Contributing\n\nTo contribute to frontend, make sure to use the [Pink Design](https://pink.appwrite.io/) design system. Ensure both dark and light theme work properly, as well as responsivity on mobile, tablet and desktop.\n\nWhen contributing with static files, ensure all images are in WEBP or SVG format.\n\n## 🖼️ Screenshots\n\n![Screenshot](docs/screenshot1.png)\n![Screenshot](docs/screenshot2.png)\n![Screenshot](docs/screenshot3.png)\n\n## 🤖 Auto-generated documentation\n\nThis is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).\n\n## Getting Started\n\nFirst, run the development server:\n\n```bash\nnpm run dev\n# or\nyarn dev\n# or\npnpm dev\n```\n\nOpen [http://localhost:3000](http://localhost:3000) with your browser to see the result.\n\nYou can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.\n\n[http://localhost:3000/api/hello](http://localhost:3000/api/hello) is an endpoint that uses [Route Handlers](https://beta.nextjs.org/docs/routing/route-handlers). This endpoint can be edited in `app/api/hello/route.ts`.\n\nThis project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.\n\n## Learn More\n\nTo learn more about Next.js, take a look at the following resources:\n\n- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.\n- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.\n\nYou can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!\n\n## Deploy on Vercel\n\nThe easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template\u0026filter=next.js\u0026utm_source=create-next-app\u0026utm_campaign=create-next-app-readme) from the creators of Next.js.\n\nCheck out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeldiron%2Fappwrite-ssr-next-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeldiron%2Fappwrite-ssr-next-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeldiron%2Fappwrite-ssr-next-js/lists"}