-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2bc106e
commit bd7bf6b
Showing
6 changed files
with
1,308 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,21 @@ | ||
# AITable | ||
|
||
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 18.0.3. | ||
## Development | ||
|
||
## Development server | ||
安装依赖 | ||
|
||
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files. | ||
``` | ||
npm install --force | ||
``` | ||
|
||
## Code scaffolding | ||
前端启动 | ||
|
||
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. | ||
``` | ||
npm run start | ||
``` | ||
|
||
## Build | ||
协同服务启动 | ||
|
||
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. | ||
|
||
## Running unit tests | ||
|
||
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). | ||
|
||
## Running end-to-end tests | ||
|
||
Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities. | ||
|
||
## Further help | ||
|
||
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page. | ||
``` | ||
npm run start-ws | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as Y from 'yjs'; | ||
import * as WebSocket from 'ws'; | ||
import http, { Server } from 'http'; | ||
const ywsUtils = require('y-websocket/bin/utils'); | ||
const setupWSConnection = ywsUtils.setupWSConnection; | ||
const docs = ywsUtils.docs as Map<string, Y.Doc & { conns: Map<any, any> }>; | ||
const port = (process.env['PORT'] || 3000) as number; | ||
|
||
const server: Server = http.createServer((request, response) => { | ||
if (request.url === '/health') { | ||
response.writeHead(200, { 'Content-Type': 'application/json' }); | ||
response.end( | ||
JSON.stringify({ | ||
response: 'ok' | ||
}) | ||
); | ||
return; | ||
} | ||
}); | ||
const wss = new WebSocket.Server({ server }); | ||
|
||
wss.on('connection', (conn, req) => { | ||
setupWSConnection(conn, req, { gc: false }); | ||
}); | ||
|
||
// log some stats | ||
setInterval(() => { | ||
let conns = 0; | ||
docs.forEach((doc) => { | ||
conns += doc.conns.size; | ||
}); | ||
const stats = { | ||
conns, | ||
docs: docs.size, | ||
websocket: `ws://localhost:${port}`, | ||
http: `http://localhost:${port}` | ||
}; | ||
console.log(`${new Date().toISOString()} Stats: ${JSON.stringify(stats)}`); | ||
}, 10000); | ||
|
||
server.listen(port, '0.0.0.0'); | ||
|
||
console.log(`Listening to http://localhost:${port}`); |
Oops, something went wrong.