-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: docs update, free book release, and small api changes * chore: version bump, dependency upgrade * Move Transmitter to Hono API #116 (#119) * added volume option to useAudio Composable (#117) * Move Transmitter to Hono API #116 * Changed / to /client for client endpoint --------- Co-authored-by: Liam Robinson <liamrobinson5@web.de> * docs: update changelog * fix: loading issue * feat: experimental dev:reload script * fix: add package.json * feat: Extendable Hono API (#122) * docs: update docs --------- Co-authored-by: Vladyslav Halatskyi <xfloydya@gmail.com> Co-authored-by: Liam Robinson <liamrobinson5@web.de>
- Loading branch information
1 parent
89f190f
commit ef896bd
Showing
15 changed files
with
370 additions
and
32 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
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
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
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
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,98 @@ | ||
--- | ||
order: 425 | ||
--- | ||
|
||
# useHono | ||
|
||
The `useHono` function is designed to extend the game-server web API server by utilizing the Hono framework. It provides mechanisms to register new routes and use middlewares for handling incoming requests. | ||
|
||
## addRouter | ||
|
||
Registers a new router with the main Hono application. | ||
|
||
```ts | ||
import { useRebar } from '@Server/index.js'; | ||
|
||
const Rebar = useRebar(); | ||
const hono = Rebar.useHono(); | ||
|
||
const app = new Hono<{ Bindings: HttpBindings }>(); | ||
|
||
// Do stuff with your Hono app. | ||
|
||
hono.addRouter('/api/v1', app); | ||
``` | ||
|
||
## midlewares | ||
|
||
A collection of middleware functions for request handling. | ||
|
||
### localOnly | ||
|
||
Middleware to restrict access to requests coming from the local machine (IP address `127.0.0.1`). | ||
|
||
```ts | ||
import { useRebar } from '@Server/index.js'; | ||
|
||
const Rebar = useRebar(); | ||
const hono = Rebar.useHono(); | ||
|
||
const app = new Hono<{ Bindings: HttpBindings }>(); | ||
|
||
app.get('/ban', hono.middlewares.localOnly, (c) => { | ||
// Handle the request | ||
}); | ||
|
||
hono.addRouter('/api/v1', app); | ||
``` | ||
|
||
> You can also build your own middlewares, such as check auth token or whatever else. | ||
## Example usage | ||
|
||
Here is an example of creating a `/ban` endpoint, that will allow you to ban an account via api. | ||
|
||
```ts | ||
import { HttpBindings } from "@hono/node-server"; | ||
import { useRebar } from "@Server/index.js"; | ||
import { Account } from "@Shared/types/account.js"; | ||
import { Hono } from "hono"; | ||
|
||
const Rebar = useRebar(); | ||
const hono = Rebar.useHono(); | ||
const app = new Hono<{ Bindings: HttpBindings }>(); | ||
|
||
app.get('/ban', hono.middlewares.localOnly, (c) => { | ||
let { reason, _id } = c.req.query(); | ||
|
||
if (!_id) { | ||
c.status(400); | ||
return c.json({ data: 'ID was not provided' }); | ||
} | ||
|
||
if (!reason) { | ||
reason = 'No Reason Given'; | ||
} | ||
|
||
const onlinePlayer = Rebar.get.usePlayerGetter().byAccount(_id); | ||
if (!onlinePlayer) { | ||
const document = Rebar.document.virtual.useVirtual<Account>(_id, Rebar.database.CollectionNames.Accounts); | ||
if (!document.get()) { | ||
c.status(400); | ||
return c.json({ data: `Account does not exist on the server` }); | ||
} else { | ||
document.setBulk({ | ||
banned: true, | ||
reason, | ||
}); | ||
} | ||
} else { | ||
const rPlayer = Rebar.usePlayer(onlinePlayer); | ||
rPlayer.account.setBanned(reason); | ||
} | ||
c.status(200); | ||
return c.json({ data: `Banned ${_id} with reason '${reason}'` }); | ||
}) | ||
|
||
hono.addRouter('/api/v1', app); | ||
``` |
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,18 @@ | ||
{ | ||
"verbose": false, | ||
"ext": "ts, vue", | ||
"watch": ["./src", "./webview"], | ||
"ignore": [ | ||
"webview/pages/*", | ||
"webview/vite.config.*", | ||
"*/package.json", | ||
"*.mjs", | ||
"ignore*.ts", | ||
"autogen*.ts", | ||
"webview/src/main.ts", | ||
"src/scratchpad" | ||
], | ||
"events": { | ||
"restart": "node ./scripts/restart.js" | ||
} | ||
} |
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,18 @@ | ||
{ | ||
"verbose": false, | ||
"ext": "ts, vue", | ||
"watch": ["./src", "./webview"], | ||
"ignore": [ | ||
"webview/pages/*", | ||
"webview/vite.config.*", | ||
"*/package.json", | ||
"*.mjs", | ||
"ignore*.ts", | ||
"autogen*.ts", | ||
"webview/src/main.ts", | ||
"src/scratchpad" | ||
], | ||
"events": { | ||
"exit": "node ./scripts/reload.js" | ||
} | ||
} |
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.