-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* first commit * improve server * improve server * fix indentation
- Loading branch information
Showing
20 changed files
with
637 additions
and
406 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,12 @@ | ||
{ | ||
"editor.codeActionsOnSave": { | ||
"source.organizeImports.biome": "explicit", | ||
"quickfix.biome": "explicit" | ||
}, | ||
"[javascript]": { | ||
"editor.defaultFormatter": "biomejs.biome" | ||
}, | ||
"[json]": { | ||
"editor.defaultFormatter": "biomejs.biome" | ||
} | ||
} |
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,94 @@ | ||
{ | ||
"$schema": "https://biomejs.dev/schemas/1.7.1/schema.json", | ||
"files": { | ||
"ignore": ["tests/fastify/**", "types/**", "dist/**"] | ||
}, | ||
"organizeImports": { "enabled": true }, | ||
"formatter": { | ||
"enabled": true | ||
}, | ||
"linter": { | ||
"ignore": ["example.js"], | ||
"enabled": true, | ||
"rules": { | ||
"recommended": false, | ||
"complexity": { | ||
"noExtraBooleanCast": "error", | ||
"noMultipleSpacesInRegularExpressionLiterals": "error", | ||
"noUselessCatch": "error", | ||
"noUselessConstructor": "error", | ||
"noUselessLoneBlockStatements": "error", | ||
"noUselessRename": "error", | ||
"noUselessTernary": "error", | ||
"noVoid": "error", | ||
"noWith": "error", | ||
"useLiteralKeys": "error", | ||
"useRegexLiterals": "error" | ||
}, | ||
"correctness": { | ||
"noConstAssign": "error", | ||
"noConstantCondition": "error", | ||
"noEmptyCharacterClassInRegex": "error", | ||
"noEmptyPattern": "error", | ||
"noGlobalObjectCalls": "error", | ||
"noInvalidConstructorSuper": "error", | ||
"noInvalidUseBeforeDeclaration": "error", | ||
"noNewSymbol": "error", | ||
"noPrecisionLoss": "error", | ||
"noSelfAssign": "error", | ||
"noSwitchDeclarations": "error", | ||
"noUndeclaredVariables": "error", | ||
"noUnreachable": "error", | ||
"noUnreachableSuper": "error", | ||
"noUnsafeFinally": "error", | ||
"noUnusedVariables": "error", | ||
"useIsNan": "error" | ||
}, | ||
"security": { "noGlobalEval": "error" }, | ||
"style": { | ||
"noCommaOperator": "error", | ||
"noVar": "warn", | ||
"useBlockStatements": "off", | ||
"useConst": "error", | ||
"useSingleVarDeclarator": "error" | ||
}, | ||
"suspicious": { | ||
"noAssignInExpressions": "error", | ||
"noAsyncPromiseExecutor": "error", | ||
"noCatchAssign": "error", | ||
"noClassAssign": "error", | ||
"noCompareNegZero": "error", | ||
"noConfusingLabels": "error", | ||
"noControlCharactersInRegex": "error", | ||
"noDebugger": "error", | ||
"noDoubleEquals": "error", | ||
"noDuplicateCase": "error", | ||
"noDuplicateClassMembers": "error", | ||
"noDuplicateObjectKeys": "error", | ||
"noDuplicateParameters": "error", | ||
"noEmptyBlockStatements": "error", | ||
"noFallthroughSwitchClause": "error", | ||
"noFunctionAssign": "error", | ||
"noGlobalAssign": "error", | ||
"noImportAssign": "error", | ||
"noMisleadingCharacterClass": "error", | ||
"noPrototypeBuiltins": "error", | ||
"noRedeclare": "error", | ||
"noSelfCompare": "error", | ||
"noShadowRestrictedNames": "error", | ||
"noUnsafeNegation": "error", | ||
"useDefaultSwitchClauseLast": "error", | ||
"useValidTypeof": "error" | ||
} | ||
} | ||
}, | ||
"javascript": { | ||
"globals": ["document", "navigator", "window"], | ||
"formatter": { | ||
"bracketSpacing": true, | ||
"indentStyle": "space", | ||
"quoteStyle": "single", | ||
"semicolons": "asNeeded" | ||
} | ||
} | ||
} |
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,58 +1,57 @@ | ||
import fastify from 'fastify' | ||
import { serverFactory, getUws, WebSocketStream } from './src/server.js' | ||
import { WebSocketStream, getUws, serverFactory } from './src/server.js' | ||
|
||
import fastifyUwsPlugin from './src/plugin.js' | ||
|
||
const app = fastify({ | ||
serverFactory | ||
serverFactory, | ||
}) | ||
|
||
await app.register(fastifyUwsPlugin) | ||
|
||
app.addHook('onReady', async () => { | ||
// access to uws app | ||
// eslint-disable-next-line no-unused-vars | ||
const uwsApp = getUws(app) | ||
}) | ||
|
||
app.websocketServer.on('open', ws => { | ||
app.websocketServer.on('open', (ws) => { | ||
console.log('OPEN') | ||
}) | ||
|
||
app.websocketServer.on('close', ws => { | ||
app.websocketServer.on('close', (ws) => { | ||
console.log('CLOSE') | ||
}) | ||
|
||
app | ||
.route({ | ||
method: 'GET', | ||
url: '/', | ||
handler (req, reply) { | ||
handler(req, reply) { | ||
return 'hello from http endpoint' | ||
}, | ||
uws: { | ||
// cache subscription topics to produce less memory allocations | ||
topics: [ | ||
'home/sensors/ligth', | ||
'home/sensors/temp' | ||
] | ||
topics: ['home/sensors/ligth', 'home/sensors/temp'], | ||
}, | ||
uwsHandler (conn) { | ||
uwsHandler(conn) { | ||
conn.subscribe('home/sensors/temp') | ||
conn.on('message', (message) => { | ||
conn.publish('home/sensors/temp', 'random message') | ||
}) | ||
conn.send(JSON.stringify({ hello: 'world' })) | ||
} | ||
}, | ||
}) | ||
.get('/stream', { uws: true }, (conn) => { | ||
const stream = new WebSocketStream(conn) | ||
stream.on('data', data => { | ||
stream.on('data', (data) => { | ||
console.log('stream data from /stream') | ||
}) | ||
}) | ||
.listen({ | ||
port: 3000 | ||
}, (err) => { | ||
err && console.error(err) | ||
}) | ||
.listen( | ||
{ | ||
port: 3000, | ||
}, | ||
(err) => { | ||
err && console.error(err) | ||
}, | ||
) |
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,93 +1,80 @@ | ||
{ | ||
"name": "@geut/fastify-uws", | ||
"version": "3.1.1", | ||
"description": "uWebSockets.js for fastify", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"types": "./types/server.d.ts", | ||
"import": "./src/server.js", | ||
"require": "./dist/server.cjs" | ||
}, | ||
"./plugin": { | ||
"types": "./types/plugin.d.ts", | ||
"import": "./src/plugin.js", | ||
"require": "./dist/plugin.cjs" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"workspaces": [ | ||
"tests/fastify/module" | ||
], | ||
"files": [ | ||
"types", | ||
"dist", | ||
"src" | ||
], | ||
"scripts": { | ||
"start": "node index.js", | ||
"build": "rm -rf dist && tsup src/server.js src/plugin.js --splitting", | ||
"test": "uvu --ignore tests/fastify", | ||
"posttest": "npm run lint && tsc", | ||
"lint": "standard", | ||
"prepublishOnly": "npm test && npm run build && npm run types", | ||
"types": "node scripts/generate-dts.js" | ||
}, | ||
"dependencies": { | ||
"fastify-plugin": "^4.5.1", | ||
"fastq": "^1.13.0", | ||
"ipaddr.js": "^2.0.1", | ||
"nanoerror": "^2.0.0", | ||
"streamx": "^2.12.5", | ||
"tempy": "^1.0.1", | ||
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.42.0" | ||
}, | ||
"devDependencies": { | ||
"@types/events": "^3.0.2", | ||
"@types/node": "^20.8.10", | ||
"@types/streamx": "^2.9.3", | ||
"execa": "^8.0.1", | ||
"fastify": "^4.24.3", | ||
"require-inject": "^1.4.4", | ||
"simple-get": "^4.0.1", | ||
"standard": "^17.0.0", | ||
"tap": "^16.3.0", | ||
"tsup": "^7.2.0", | ||
"typescript": "^5.2.2", | ||
"uvu": "^0.5.3", | ||
"ws": "^8.9.0" | ||
}, | ||
"standard": { | ||
"env": [ | ||
"node", | ||
"browser" | ||
], | ||
"ignore": [ | ||
"tests/fastify/**" | ||
] | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/geut/fastify-uws.git" | ||
}, | ||
"keywords": [ | ||
"fastify", | ||
"uWebSockets.js", | ||
"fastify-plugin" | ||
], | ||
"author": { | ||
"name": "GEUT", | ||
"email": "[email protected]" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/geut/fastify-uws/issues" | ||
}, | ||
"homepage": "https://github.com/geut/fastify-uws#readme", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"engines": { | ||
"node": ">=18" | ||
} | ||
"name": "@geut/fastify-uws", | ||
"version": "3.1.1", | ||
"description": "uWebSockets.js for fastify", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"types": "./types/server.d.ts", | ||
"import": "./src/server.js", | ||
"require": "./dist/server.cjs" | ||
}, | ||
"./plugin": { | ||
"types": "./types/plugin.d.ts", | ||
"import": "./src/plugin.js", | ||
"require": "./dist/plugin.cjs" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"workspaces": ["tests/fastify/module"], | ||
"files": ["types", "dist", "src"], | ||
"scripts": { | ||
"start": "node index.js", | ||
"build": "rm -rf dist && tsup src/server.js src/plugin.js --splitting", | ||
"test": "uvu --ignore tests/fastify", | ||
"posttest": "npm run lint && tsc", | ||
"lint": "biome check .", | ||
"lint:fix": "biome check --apply .", | ||
"prepublishOnly": "npm test && npm run build && npm run types", | ||
"types": "node scripts/generate-dts.js" | ||
}, | ||
"dependencies": { | ||
"fastify-plugin": "^4.5.1", | ||
"fastq": "^1.13.0", | ||
"ipaddr.js": "^2.0.1", | ||
"nanoerror": "^2.0.0", | ||
"streamx": "^2.12.5", | ||
"tempy": "^1.0.1", | ||
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.42.0" | ||
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "^1.7.3", | ||
"@fastify/static": "^7.0.3", | ||
"@types/events": "^3.0.2", | ||
"@types/node": "^20.8.10", | ||
"@types/streamx": "^2.9.3", | ||
"execa": "^8.0.1", | ||
"fastify": "^4.24.3", | ||
"require-inject": "^1.4.4", | ||
"simple-get": "^4.0.1", | ||
"tap": "^16.3.0", | ||
"tsup": "^7.2.0", | ||
"typescript": "^5.2.2", | ||
"uvu": "^0.5.3", | ||
"ws": "^8.9.0" | ||
}, | ||
"standard": { | ||
"env": ["node", "browser"], | ||
"ignore": ["tests/fastify/**"] | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/geut/fastify-uws.git" | ||
}, | ||
"keywords": ["fastify", "uWebSockets.js", "fastify-plugin"], | ||
"author": { | ||
"name": "GEUT", | ||
"email": "[email protected]" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/geut/fastify-uws/issues" | ||
}, | ||
"homepage": "https://github.com/geut/fastify-uws#readme", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"engines": { | ||
"node": ">=18" | ||
} | ||
} |
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
Oops, something went wrong.