tauri-nextjs-api-routes
tauri-nextjs-api-routes copied to clipboard
Next JS API routes with Tauri Example
This repo demonstrates how you can use Next JS and Tauri together to build an application which can be deployed on the web, and also packaged up as a desktop application. Since Tauri usually doesn't support NextJS API routes, this example shows how to share code and logic between NextJS API routes and a local server used in the Tauri application.
To achieve this, the pkg package is used to package up a node server as a binary. This binary is then used as a sidecar in the Tauri application.
For simplicity, I decided to write the server using express, but you can use any server you want.
Screenshot
Tauri

Web

Getting Started
- Clone the repo
git clone [email protected]:srsholmes/tauri-nextjs-api-routes.git. - Install dependencies using
npm installoryarnorpnpm install.
To run NextJS Application:
npm run dev # or yarn dev
To run the Tauri application (dev):
npm run tauri dev # or yarn tauri dev
To build the Tauri application:
npm run tauri build # or yarn tauri build
To build the server for tauri:
npm run package:server # or yarn package:server
Architecture
- The Next JS application is run using
npm run devand is available athttp://localhost:3000. - The Tauri application is run using
npm run tauri dev. The Tauri application uses thepkg-generated binary to run a local server on the user's machine. - The NextJS API routes are normally not supported by Tauri, but by running the local server as a sidecar using the binary generated by
pkg, the Tauri application is able to access the routes and their functionality. - Shared code between Tauri and NextJS is located in the
src/shareddirectory, while code for NextJS API routes and pages is located in thepages/apidirectory. - The tauri server is located in the
serverdirectory.
Technologies Used
License
MIT