Create WebSocket Server
- Created a WebSocket server with connection handling and message broadcasting - Added frontend files including HTML, TypeScript, and CSS for a WebSocket test client - Configured package.json for both server and frontend with necessary scripts and dependencies - Introduced Prettier configuration for code formatting - Established a basic structure for handling WebSocket connections and messages
This commit is contained in:
13
frontend/web/index.html
Normal file
13
frontend/web/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + TS</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
15
frontend/web/package.json
Normal file
15
frontend/web/package.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "web",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc && vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "~5.8.3",
|
||||
"vite": "^7.1.2"
|
||||
}
|
||||
}
|
||||
13
frontend/web/src/main.ts
Normal file
13
frontend/web/src/main.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
const webSocket = new WebSocket('http://localhost:3000');
|
||||
|
||||
webSocket.onerror = (e: Event) => {
|
||||
console.error(`${new Date().toISOString()} [WebSocket] error [%o]`, e);
|
||||
};
|
||||
|
||||
webSocket.onopen = () => {
|
||||
console.log(`${new Date().toISOString()} [WebSocket] open`);
|
||||
};
|
||||
|
||||
webSocket.onmessage = () => {
|
||||
console.log(`${new Date().toISOString()} [WebSocket] message!`);
|
||||
};
|
||||
4
frontend/web/src/style.css
Normal file
4
frontend/web/src/style.css
Normal file
@@ -0,0 +1,4 @@
|
||||
body {
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
1
frontend/web/src/vite-env.d.ts
vendored
Normal file
1
frontend/web/src/vite-env.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
||||
25
frontend/web/tsconfig.json
Normal file
25
frontend/web/tsconfig.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
Reference in New Issue
Block a user