├── .gitignore ├── frontend ├── .env.development ├── .eslintrc.json ├── postcss.config.js ├── public │ ├── chatroom.png │ └── powered-by-vercel.svg ├── src │ ├── app │ │ ├── favicon.ico │ │ ├── globals.css │ │ ├── emotion.tsx │ │ ├── layout.tsx │ │ ├── provide.tsx │ │ ├── page.tsx │ │ └── home │ │ │ └── page.tsx │ ├── config │ │ └── index.ts │ ├── store │ │ ├── basic.ts │ │ └── socket.ts │ ├── types │ │ └── next.ts │ ├── components │ │ ├── NameModal.tsx │ │ ├── Avatar.tsx │ │ ├── ChatroomInput.tsx │ │ └── ChatroomTitle.tsx │ └── pages │ │ └── api │ │ └── socket │ │ └── socketio.ts ├── .env.production ├── next.config.js ├── .gitignore ├── tailwind.config.js ├── tsconfig.json ├── package.json └── README.md ├── backend ├── README.md ├── .prettierignore ├── .eslintignore ├── .env.production ├── .env.development ├── .prettierrc ├── .env.example ├── src │ ├── config.ts │ ├── core │ │ ├── ApiError.ts │ │ ├── Logger.ts │ │ └── ApiResponse.ts │ ├── app.ts │ └── server.ts ├── .gitignore ├── .eslintrc ├── package.json ├── tsconfig.json └── pnpm-lock.yaml ├── LICENSE ├── README.tw.md └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /**/node_modules -------------------------------------------------------------------------------- /frontend/.env.development: -------------------------------------------------------------------------------- 1 | NEXT_PUBLIC_SOCKET_URL=/ -------------------------------------------------------------------------------- /backend/README.md: -------------------------------------------------------------------------------- 1 | # Socket.io Node.js Backend Typescript Project -------------------------------------------------------------------------------- /frontend/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals" 3 | } 4 | -------------------------------------------------------------------------------- /backend/.prettierignore: -------------------------------------------------------------------------------- 1 | build/ 2 | coverage/ 3 | keys/ 4 | logs/ 5 | node_modules/ 6 | *.md -------------------------------------------------------------------------------- /backend/.eslintignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | 3 | node_modules/ 4 | 5 | # Build products 6 | build/ 7 | dist/ 8 | tools/ -------------------------------------------------------------------------------- /frontend/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /frontend/public/chatroom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ttpss930141011/nextjs-13-socketio-template/HEAD/frontend/public/chatroom.png -------------------------------------------------------------------------------- /frontend/src/app/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ttpss930141011/nextjs-13-socketio-template/HEAD/frontend/src/app/favicon.ico -------------------------------------------------------------------------------- /frontend/src/config/index.ts: -------------------------------------------------------------------------------- 1 | export const SOCKET_URL = process.env.NEXT_PUBLIC_SOCKET_URL; 2 | export const environment = process.env.NODE_ENV; -------------------------------------------------------------------------------- /backend/.env.production: -------------------------------------------------------------------------------- 1 | # Environment Name 2 | NODE_ENV=production 3 | 4 | # Server listen to this port 5 | PORT=3001 6 | 7 | #Cors 8 | CORS_URL=* -------------------------------------------------------------------------------- /backend/.env.development: -------------------------------------------------------------------------------- 1 | # Environment Name 2 | NODE_ENV=development 3 | 4 | # Server listen to this port 5 | PORT=3001 6 | 7 | #Cors 8 | CORS_URL=* -------------------------------------------------------------------------------- /frontend/src/app/globals.css: -------------------------------------------------------------------------------- 1 | /* @tailwind base; */ 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | textarea::-webkit-scrollbar { 6 | width: 0; 7 | } 8 | -------------------------------------------------------------------------------- /backend/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "useTabs": false, 3 | "semi": true, 4 | "trailingComma": "all", 5 | "singleQuote": true, 6 | "printWidth": 80, 7 | "tabWidth": 2 8 | } 9 | -------------------------------------------------------------------------------- /backend/.env.example: -------------------------------------------------------------------------------- 1 | # .env.example 2 | 3 | # Environment Name 4 | NODE_ENV=development 5 | 6 | # Server listen to this port 7 | PORT=3000 8 | 9 | #Cors 10 | CORS_URL=* 11 | -------------------------------------------------------------------------------- /frontend/.env.production: -------------------------------------------------------------------------------- 1 | # if you wanna deploy to Vercel, you need to host bankend and replace the url or create a new .env.production.local file 2 | NEXT_PUBLIC_SOCKET_URL=ws://localhost:3001 -------------------------------------------------------------------------------- /backend/src/config.ts: -------------------------------------------------------------------------------- 1 | // Mapper for environment variables 2 | export const environment = process.env.NODE_ENV; 3 | export const port = process.env.PORT; 4 | export const corsUrl = process.env.CORS_URL; 5 | export const logDirectory = process.env.LOG_DIR; -------------------------------------------------------------------------------- /frontend/next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const nextConfig = { 3 | webpack: (config) => { 4 | 5 | config.externals.push({ 6 | 'utf-8-validate': 'commonjs utf-8-validate', 7 | bufferutil: 'commonjs bufferutil', 8 | }) 9 | 10 | return config 11 | }, 12 | } 13 | 14 | module.exports = nextConfig -------------------------------------------------------------------------------- /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | 27 | # local env files 28 | .env*.local 29 | 30 | # vercel 31 | .vercel 32 | 33 | # typescript 34 | *.tsbuildinfo 35 | next-env.d.ts 36 | -------------------------------------------------------------------------------- /frontend/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: [ 4 | './src/pages/**/*.{js,ts,jsx,tsx,mdx}', 5 | './src/components/**/*.{js,ts,jsx,tsx,mdx}', 6 | './src/app/**/*.{js,ts,jsx,tsx,mdx}', 7 | ], 8 | theme: { 9 | extend: { 10 | backgroundImage: { 11 | 'gradient-radial': 'radial-gradient(var(--tw-gradient-stops))', 12 | 'gradient-conic': 13 | 'conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))', 14 | }, 15 | }, 16 | }, 17 | plugins: [], 18 | } 19 | -------------------------------------------------------------------------------- /backend/.gitignore: -------------------------------------------------------------------------------- 1 | # Add any directories, files, or patterns you don't want to be tracked by version control 2 | .idea 3 | 4 | # ignore vs code project config files 5 | .vs 6 | 7 | # ignore logs 8 | logs 9 | *.log 10 | 11 | # ignore 3rd party lib 12 | node_modules 13 | 14 | # ignore key 15 | *.pem 16 | 17 | # Ignore built files 18 | build 19 | 20 | # ignore test converage 21 | coverage 22 | 23 | # Environment varibles 24 | *.env 25 | *.env.test 26 | *.env copy 27 | 28 | #keys 29 | keys/* 30 | !keys/*.md 31 | !keys/*.example 32 | 33 | #temp 34 | temp 35 | .DS_Store 36 | 37 | *.save 38 | *.save.* -------------------------------------------------------------------------------- /frontend/src/app/emotion.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | 3 | import { CacheProvider } from "@emotion/react"; 4 | import { useEmotionCache } from "@mantine/core"; 5 | import { useServerInsertedHTML } from "next/navigation"; 6 | 7 | export default function RootStyleRegistry({ children }: { children: React.ReactNode }) { 8 | const cache = useEmotionCache(); 9 | cache.compat = true; 10 | 11 | useServerInsertedHTML(() => ( 12 |