Skip to content

Commit 2bf4525

Browse files
committed
Fix global middleware
1 parent 326da5e commit 2bf4525

File tree

9 files changed

+24
-14
lines changed

9 files changed

+24
-14
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 3.0.10
2+
- ServerGlobalMiddleware should now function :-)
3+
14
## 3.0.6
25
- Fixes (https://github.com/roblox-aurora/rbx-net/pull/84) `Client:Get(remoteId) causing delays`
36

example/client/index.client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ const testEvents = Remotes.Client.GetNamespace("TestingEvents");
66

77
const add = testFunctions.Get("CallServerAndAddNumbers");
88

9-
add.CallServerAsync(10, 10).then((result) => {
9+
add.CallServerAsync(10, 10).then(result => {
1010
if (result === 20) {
1111
print("RESULT IS 20");
1212
} else {
13-
error("RESULT IS WRONG");
13+
error("RESULT IS WRONG " + tostring(result));
1414
}
1515
});
16+
17+
testEvents.Get("PrintMessage").SendToServer("Hwello, World!");

example/server/index.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const testEvents = Remotes.Server.GetNamespace("TestingEvents");
99
testFunctions.OnFunction("CallServerAndAddNumbers", (_, a, b) => a + b);
1010
testEvents.OnEvent("PrintMessage", print);
1111
const testLegacy = Remotes.Server.GetNamespace("Legacy").Create("LegacyFunction");
12-
const testLegacy2 = Remotes.Client.GetNamespace("Legacy").Get("LegacyFunction");
12+
// const testLegacy2 = Remotes.Client.GetNamespace("Legacy").Get("LegacyFunction");
1313

1414
testFunctions.Create("CallServerAndAddNumbers").SetCallback((_, a, b) => a + b);
1515

@@ -21,7 +21,7 @@ type NamespaceTest = Net.Util.GetNamespaceDefinitions<GlobalNamespace, "TestingE
2121
type TestNamespaceAsServerRemotes = Net.Util.GetServerRemotes<NamespaceTest>;
2222
type TestNamespaceAsClientRemotes = Net.Util.GetClientRemotes<NamespaceTest>;
2323

24-
Remotes.Server.Get("Srv").Connect((message) => {});
24+
Remotes.Server.Get("Srv").Connect(message => {});
2525

2626
Remotes.Server.GetNamespace("TestingFunctions").OnFunction("CallServerAndAddNumbers", async () => {
2727
return 10;

example/shared/definitions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const Remotes = Create(
4141
{
4242
ServerGlobalMiddleware: [
4343
Net.Middleware.Global((remote, data, player) => {
44-
$print("call from", player, "via", remote, ...data);
44+
$print("**** call from", player, "via", remote, ...data);
4545
}),
4646
],
4747
},

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rbxts/net",
3-
"version": "3.0.9",
3+
"version": "3.0.10",
44
"description": "",
55
"main": "out/init.lua",
66
"scripts": {
@@ -13,8 +13,8 @@
1313
"build:dev": "cross-env NODE_ENV=development rbxtsc --verbose",
1414
"watch:dev": "cross-env NODE_ENV=development rbxtsc -w --verbose",
1515
"build:rbxmx": "npm run build:luau && rojo build luau/build.project.json -o luau.net.rbxmx",
16-
"build:example": "cross-env NODE_ENV=development rbxtsc-dev --type=game -p ./example -i ./include",
17-
"watch:example": "cross-env NODE_ENV=development TYPE=TestTS rbxtsc-dev -w --type=game -p ./example -i ./include",
16+
"build:example": "cross-env NODE_ENV=development rbxtsc --type=game -p ./example -i ./include",
17+
"watch:example": "cross-env NODE_ENV=development TYPE=TestTS rbxtsc -w --type=game -p ./example -i ./include",
1818
"serve:example": "rojo serve ./example/default.project.json --port 34567",
1919
"dev:example": "concurrently npm:watch:example npm:serve:example"
2020
},

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ namespace Net {
130130
/**
131131
* The version of RbxNet
132132
*/
133-
export const VERSION = $NODE_ENV === "production" ? PKG_VERSION : `DEV ${DIST})} ${PKG_VERSION}`;
133+
export const VERSION = ($NODE_ENV as string) === "production" ? PKG_VERSION : `DEV ${DIST})} ${PKG_VERSION}`;
134134

135135
/**
136136
* Built-in middlewares

src/server/ServerEvent.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import MiddlewareEvent, { MiddlewareList } from "./MiddlewareEvent";
44
import { MiddlewareOverload } from "../middleware";
55
import { NetServerScriptSignal, NetServerSignalConnection } from "./NetServerScriptSignal";
66
import { DefinitionConfiguration } from "../definitions";
7+
import { $dbg } from "rbxts-transform-debug";
78

89
/**
910
* Interface for server listening events
@@ -62,7 +63,7 @@ export default class ServerEvent<
6263
middlewares: MiddlewareOverload<ConnectArgs> = [],
6364
private configuration: DefinitionConfiguration,
6465
) {
65-
super(middlewares);
66+
super([...middlewares, ...(configuration.ServerGlobalMiddleware ?? [])]);
6667
assert(!IS_CLIENT, "Cannot create a NetServerEvent on the client!");
6768
this.instance = findOrCreateRemote("RemoteEvent", name);
6869
this.connection = new NetServerScriptSignal(this.instance.OnServerEvent, this.instance);

src/server/ServerFunction.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ export default class ServerFunction<
1717
return undefined;
1818
};
1919

20-
constructor(name: string, middlewares: MiddlewareOverload<CallbackArgs> = [], private configuration: DefinitionConfiguration) {
20+
constructor(
21+
name: string,
22+
middlewares: MiddlewareOverload<CallbackArgs> = [],
23+
private configuration: DefinitionConfiguration,
24+
) {
2125
super(middlewares);
22-
this.instance = findOrCreateRemote("RemoteFunction", name, (instance) => {
26+
this.instance = findOrCreateRemote("RemoteFunction", name, instance => {
2327
// Default listener
2428
instance.OnServerInvoke = ServerFunction.DefaultFunctionHook;
2529
CollectionService.AddTag(instance, TagId.DefaultFunctionListener);

0 commit comments

Comments
 (0)