mirror of
https://github.com/thib8956/tic-tac-toe-ws.git
synced 2026-03-24 14:37:56 +00:00
fix: improve npm scripts and fix localhost detection
This commit is contained in:
5
.github/workflows/main.yml
vendored
5
.github/workflows/main.yml
vendored
@@ -15,10 +15,7 @@ jobs:
|
|||||||
- name: Install and Build
|
- name: Install and Build
|
||||||
run: |
|
run: |
|
||||||
npm ci
|
npm ci
|
||||||
npx tsc
|
npm run build
|
||||||
mkdir dist
|
|
||||||
mv *.js dist/
|
|
||||||
mv *.html dist/
|
|
||||||
- name: Setup Pages
|
- name: Setup Pages
|
||||||
id: pages
|
id: pages
|
||||||
uses: actions/configure-pages@v5
|
uses: actions/configure-pages@v5
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
*.js
|
dist/
|
||||||
|
|
||||||
|
|||||||
18
README.md
18
README.md
@@ -1,21 +1,17 @@
|
|||||||
# Tic tac toe websockets
|
# Tic tac toe websockets
|
||||||
|
|
||||||
Two players tic-tac-joe implemented with an HTML canvas and websockets
|
Two players tic-tac-joe implemented with an HTML canvas and websockets
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
## How to run
|
## How to run
|
||||||
|
|
||||||
```
|
```shell
|
||||||
// compilation of .mts files in watch mode
|
$ npm run build:watch
|
||||||
$ tsc -w
|
|
||||||
|
|
||||||
// serve static files (localhost:8000)
|
// serve static files (localhost:8000)
|
||||||
$ python serve.py
|
$ npm run serve
|
||||||
|
|
||||||
// run server
|
// run server
|
||||||
$ node server.mjs
|
$ npm run start:watch
|
||||||
```
|
```
|
||||||
|
|
||||||
Go to http://localhost:8000
|
Go to [](http://localhost:8000)
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,9 @@ const ANIMATE_DURATION = 500; // ms
|
|||||||
const GRID_PADDING = 10;
|
const GRID_PADDING = 10;
|
||||||
const MESSAGE_PADDING = 20;
|
const MESSAGE_PADDING = 20;
|
||||||
|
|
||||||
let address = "ws://localhost:1234";
|
const address = ["127.0.0.1", "localhost"].includes(window.location.hostname)
|
||||||
if (window.location.hostname !== "localhost") {
|
? "ws://localhost:1234"
|
||||||
address = "wss://tic-tac-toe-ws-production.up.railway.app";
|
: "wss://tic-tac-toe-ws-production.up.railway.app";
|
||||||
}
|
|
||||||
const ws = new WebSocket(address);
|
const ws = new WebSocket(address);
|
||||||
|
|
||||||
interface Point {
|
interface Point {
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
export type MessageKind = "click" | "hello" | "update" | "endgame" | "reset" | "spectate";
|
|
||||||
|
|
||||||
export type Message =
|
export type Message =
|
||||||
| { kind: "click", data: Click }
|
| { kind: "click", data: Click }
|
||||||
| { kind: "hello", data: Hello }
|
| { kind: "hello", data: Hello }
|
||||||
|
|||||||
@@ -5,8 +5,11 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "tsc && cp index.html dist/",
|
||||||
"start": "node server.js"
|
"build:watch": "tsc --watch && cp index.html dist/",
|
||||||
|
"start": "node dist/server.js",
|
||||||
|
"start:watch": "node --watch dist/server.js",
|
||||||
|
"serve": "python serve.py"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
|
|||||||
8
serve.py
8
serve.py
@@ -1,11 +1,7 @@
|
|||||||
import http.server
|
import http.server
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
HandlerClass = http.server.SimpleHTTPRequestHandler
|
HandlerClass = partial(http.server.SimpleHTTPRequestHandler, directory="dist/")
|
||||||
|
|
||||||
# Patch in the correct extensions
|
|
||||||
HandlerClass.extensions_map['.js'] = 'text/javascript'
|
|
||||||
HandlerClass.extensions_map['.mjs'] = 'text/javascript'
|
|
||||||
|
|
||||||
# Run the server (like `python -m http.server` does)
|
# Run the server (like `python -m http.server` does)
|
||||||
http.server.test(HandlerClass, port=8000)
|
http.server.test(HandlerClass, port=8000)
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@
|
|||||||
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
||||||
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
||||||
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
||||||
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
||||||
// "removeComments": true, /* Disable emitting comments. */
|
// "removeComments": true, /* Disable emitting comments. */
|
||||||
// "noEmit": true, /* Disable emitting files from a compilation. */
|
// "noEmit": true, /* Disable emitting files from a compilation. */
|
||||||
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
||||||
@@ -104,5 +104,7 @@
|
|||||||
/* Completeness */
|
/* Completeness */
|
||||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||||
}
|
},
|
||||||
|
"include": ["./**/*.ts"],
|
||||||
|
"exclude": ["node_modules", "dist"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user