Skip to content

Commit

Permalink
firts commit
Browse files Browse the repository at this point in the history
  • Loading branch information
srsholmes committed Mar 29, 2023
1 parent d4b783a commit 731c519
Show file tree
Hide file tree
Showing 41 changed files with 44,697 additions and 783 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts
.idea
dist
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.12
64 changes: 44 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,62 @@
This 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).
# Next JS 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
![img.png](resources/tauri.png)

### Web
![img.png](resources/web.png)


## Getting Started

First, run the development server:
1. Clone the repo `git clone [email protected]:srsholmes/tauri-nextjs-api-routes.git`.
2. Install dependencies using `npm install` or `yarn` or `pnpm install`.

## To run NextJS Application:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
npm run dev # or yarn dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
## To run the Tauri application (dev):

You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.
```bash
npm run tauri dev # or yarn tauri dev
```

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.
## To build the Tauri application:

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
```bash
npm run tauri build # or yarn tauri build
```

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
## To build the server for tauri:

## Learn More
```bash
npm run package:server # or yarn package:server
```

To learn more about Next.js, take a look at the following resources:
## Architecture

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
- The Next JS application is run using `npm run dev` and is available at `http://localhost:3000`.
- The Tauri application is run using `npm run tauri dev`. The Tauri application uses the `pkg`-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/shared` directory, while code for NextJS API routes and pages is located in the `pages/api` directory.
- The tauri server is located in the `server` directory.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
## Technologies Used

## Deploy on Vercel
- [Next JS](https://nextjs.org/)
- [Tauri](https://tauri.studio/)
- [pkg](https://github.com/vercel/pkg)

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
## License

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
MIT
12 changes: 12 additions & 0 deletions build-server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as esbuild from 'esbuild';

(async () => {
await esbuild.build({
entryPoints: ['./server/server.ts'],
bundle: true,
platform: 'node',
target: ['node18.0'],
outfile: 'dist/server/server.js',
plugins: [],
});
})();
Loading

0 comments on commit 731c519

Please sign in to comment.