Skip to content

Commit

Permalink
refactor frontend env NEXT_PUBLIC_BASE_PATH NEXT_PUBLIC_SOCKETIO_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
huoyijie committed Aug 15, 2023
1 parent b1b5273 commit 49721ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/nextjs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ jobs:
- name: Build with Next.js
run: ${{ steps.detect-package-manager.outputs.runner }} next build
env:
NEXT_PUBLIC_SOCKETIO_URL: wss://huoyijie.cn:1024/infinity
NEXT_PUBLIC_SOCKETIO_URL: wss://huoyijie.cn:1024
NEXT_PUBLIC_BASE_PATH: /infinity
- name: Static HTML export with Next.js
run: ${{ steps.detect-package-manager.outputs.runner }} next export
- name: Upload artifact
Expand Down
7 changes: 6 additions & 1 deletion frontend/components/WB.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import io from 'socket.io-client';
import msgpackParser from 'socket.io-msgpack-parser';
import { LazyBrush } from 'lazy-brush';
import { v4 as uuidv4 } from 'uuid';
import path from 'path';

// 通过 uuid 生成 stroke id
const newStrokeId = () => uuidv4().replaceAll('-', '');
Expand Down Expand Up @@ -117,9 +118,13 @@ export default {
this.lbCanvas.addEventListener('touchend', (e) => that.touchEnd(), false);
this.lbCanvas.addEventListener('touchcancel', (e) => that.touchEnd(), false);

const socketioUrl = process.env.NEXT_PUBLIC_SOCKETIO_URL || 'ws://localhost:5000';
// basePath must start with '/'
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || '/';
// 建立 socket.io 连接
this.socket = io(process.env.NEXT_PUBLIC_SOCKETIO_URL || 'ws://localhost:4000', {
this.socket = io(socketioUrl, {
parser: msgpackParser,
path: path.join(basePath, 'socket.io')
});
this.socket.on('drawings', (drawings) => {
that.onRecvDrawings(drawings);
Expand Down

0 comments on commit 49721ca

Please sign in to comment.