2 |
3 |
4 |
5 | nextjs-13-socketio-boilerplate
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | 
15 |
16 |
17 |
18 |
19 |
20 | 
21 | 
22 | 
23 | 
24 |
25 | English Readme |
繁體中文 Readme
26 |
27 |
28 |
29 | ## 📍 Overview
30 |
31 | The project is a boilerplate for building real-time chat applications using Next.js 13(app router) and Socket.IO.
32 | It can automatically switch API based on `npm run prod` or `npm run dev`.
33 | On the backend, It provides a simple Express server-side setup to simulate a production environment when using `npm run prod`. Or it will use mocked Socket.io API in development enviroment.
34 | On the frontend, I encasulate Socket.IO hander into a lightweight state management library [Zustand](https://zustand-demo.pmnd.rs/) and invoke them in chatroom components.
35 | The project aims to streamline the development of real-time chat applications by providing a foundation with essential features and integrations.
36 |
37 | ## 🚀 Getting Started
38 |
39 | ### 🖥 Installation
40 |
41 | 1. Clone the nextjs-13-socketio-boilerplate repository:
42 |
43 | ```sh
44 | git clone https://github.com/ttpss930141011/nextjs-13-socketio-boilerplate
45 | ```
46 |
47 | 2. Change to the project directory:
48 |
49 | ```sh
50 | cd nextjs-13-socketio-boilerplate/frontend
51 | # and
52 | cd nextjs-13-socketio-boilerplate/backend
53 | ```
54 |
55 | 3. Install the dependencies:
56 |
57 | ```sh
58 | pnpm install
59 | ```
60 |
61 | ### 🤖 Using nextjs-13-socketio-boilerplate
62 |
63 | On the backend, you need to customize your enviroment variables certainly based on OS in package.json.
64 | For me, my os is windows, so in the dev command it have a **SET** NODE_ENV=development command but it don't need it Linux/Mac.
65 |
66 | #### Development enviroment
67 |
68 | In development, frontend will rise a request to its mocked api server but backend server.
69 |
70 | > Hint: Or you can use `npm run prod` in frontend and change **NEXT_PUBLIC_SOCKET_URL** as `ws://localhost:3001` in .env.production to rise a request to backend server.
71 |
72 | ```sh
73 | # frondend
74 | npm run dev
75 | # backend
76 | npm run dev
77 | ```
78 |
79 | #### Production enviroment
80 |
81 | In production, frontend will rise a request to express backend server.
82 |
83 | ```sh
84 | # frondend
85 | npm run prod
86 | # backend
87 | npm run prod
88 | ```
89 |
90 | ### Deploy nextjs-13-socketio-boilerplate
91 |
92 | #### Backend deployment
93 |
94 | I deploy the backend project in [Render](https://dashboard.render.com/).
95 | Render is a cloud application hosting service company designed for developers. It provides a simple and easy-to-use platform that allows developers to quickly and easily deploy their applications to the cloud. Render's services include:
96 |
97 | - Automatic deployment: Render can automatically deploy your application to the cloud without any manual intervention.
98 | - Automatic scaling: Render can automatically scale your application to meet your needs without any manual management.
99 | - Automatic monitoring: Render can automatically monitor your application and notify you when problems occur.
100 | - Automatic backup: Render can automatically backup your application to prevent accidental loss.
101 |
102 | The following is the parameters suggestions when setting backend project.
103 |
104 | | Type | Parameter |
105 | | :--------------- | :----------------------------------------- |
106 | | `Name` | `