Skip to content

Commit

Permalink
Add reverse proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed May 9, 2023
1 parent 0b9a9d7 commit 7bd01a0
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 13 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ jobs:
Get-Content pubspec.yaml | Select-String -Pattern 'version:\s(.+)\+' | % {Set-Item -Path Env:QECK_VERSION -Value "$($_.matches.groups[1])"}
& 'C:/Program Files (x86)/Inno Setup 6/ISCC.exe' /DMyAppVersion=$Env:QECK_VERSION QeckSetup.iss
# flutter pub run msix:create
- name: Copy portable start script
run: |
cp scripts/start.bat build/windows/runner/Release/
#- name: Copy portable start script
# run: |
# cp scripts/start.bat build/windows/runner/Release/
- name: Archive
uses: actions/upload-artifact@v3
with:
Expand Down Expand Up @@ -190,9 +190,9 @@ jobs:
run: |
ls
mv ./*.AppImage linwood-qeck-linux.AppImage
- name: Copy portable start script
run: |
cp scripts/start.sh build/linux/x64/release/bundle
#- name: Copy portable start script
# run: |
# cp scripts/start.sh build/linux/x64/release/bundle
- name: Archive
uses: actions/upload-artifact@v3
with:
Expand Down
5 changes: 1 addition & 4 deletions app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,5 @@
.pub/
/build/

# Web related
lib/generated_plugin_registrant.dart

# Exceptions to above rules.
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
4 changes: 3 additions & 1 deletion app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@
"count": "Count",
"putCards": "Put cards",
"changeVisibility": "Change visibility",
"change": "Change"
"change": "Change",
"secure": "Secure",
"port": "Port"
}
22 changes: 20 additions & 2 deletions app/lib/pages/home/connect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class ConnectGameDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
var currentAddress = '';
var port = kDefaultPort;
bool secure = false;
return AlertDialog(
title: Text(AppLocalizations.of(context).create),
scrollable: true,
Expand All @@ -17,6 +19,11 @@ class ConnectGameDialog extends StatelessWidget {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
CheckboxListTile(
title: Text(AppLocalizations.of(context).secure),
value: secure,
onChanged: (value) => secure = value ?? secure,
),
TextFormField(
decoration: InputDecoration(
labelText: AppLocalizations.of(context).address,
Expand All @@ -26,6 +33,16 @@ class ConnectGameDialog extends StatelessWidget {
initialValue: currentAddress,
onChanged: (value) => currentAddress = value,
),
const SizedBox(height: 16),
TextFormField(
decoration: InputDecoration(
labelText: AppLocalizations.of(context).port,
filled: true,
icon: const PhosphorIcon(PhosphorIconsLight.textT),
),
initialValue: port.toString(),
onChanged: (value) => port = int.tryParse(value) ?? port,
),
],
),
),
Expand All @@ -36,9 +53,10 @@ class ConnectGameDialog extends StatelessWidget {
),
ElevatedButton(
onPressed: () => Navigator.of(context).pop(Uri(
scheme: 'ws',
scheme: secure ? 'wss' : 'ws',
host: currentAddress,
port: kDefaultPort,
port: port,
path: '/connect',
)),
child: Text(AppLocalizations.of(context).create),
),
Expand Down
39 changes: 39 additions & 0 deletions tools/local_server.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'dart:io';

import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_static/shelf_static.dart';
import 'package:shelf_web_socket/shelf_web_socket.dart';
import 'package:web_socket_channel/web_socket_channel.dart';

void main() {
final staticHandler =
createStaticHandler('app/build/web', defaultDocument: 'index.html');

final socketHandler = webSocketHandler((WebSocketChannel webSocket) async {
final proxied = await WebSocket.connect('ws://localhost:10357');
webSocket.stream.listen((message) {
proxied.add(message);
}, onDone: () {
proxied.close();
});
proxied.listen((message) {
webSocket.sink.add(message);
}, onDone: () {
webSocket.sink.close();
});
});

// Serve /connect requests with the web socket handler.
// Serve other requests with the static file handler.
handler(Request request) {
print(request.url.path);
if (request.url.path == 'connect') {
return socketHandler(request);
} else {
return staticHandler(request);
}
}

io.serve(handler, 'localhost', 80);
}
112 changes: 112 additions & 0 deletions tools/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.4.1"
async:
dependency: transitive
description:
name: async
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
url: "https://pub.dev"
source: hosted
version: "2.11.0"
clock:
dependency: transitive
description:
Expand All @@ -25,6 +33,38 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.17.1"
convert:
dependency: transitive
description:
name: convert
sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592"
url: "https://pub.dev"
source: hosted
version: "3.1.1"
crypto:
dependency: transitive
description:
name: crypto
sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab
url: "https://pub.dev"
source: hosted
version: "3.0.3"
http:
dependency: transitive
description:
name: http
sha256: "5895291c13fa8a3bd82e76d5627f69e0d85ca6a30dcac95c4ea19a5d555879c2"
url: "https://pub.dev"
source: hosted
version: "0.13.6"
http_parser:
dependency: transitive
description:
name: http_parser
sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b"
url: "https://pub.dev"
source: hosted
version: "4.0.2"
intl:
dependency: "direct main"
description:
Expand All @@ -49,6 +89,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.9.1"
mime:
dependency: transitive
description:
name: mime
sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e
url: "https://pub.dev"
source: hosted
version: "1.0.4"
path:
dependency: transitive
description:
Expand All @@ -57,6 +105,38 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.8.3"
shelf:
dependency: "direct main"
description:
name: shelf
sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4
url: "https://pub.dev"
source: hosted
version: "1.4.1"
shelf_proxy:
dependency: "direct main"
description:
name: shelf_proxy
sha256: cf9883f9ec7fe9d3fb076724d627dd5d9a3c8d07cde7ef5c3f51813d1d732abe
url: "https://pub.dev"
source: hosted
version: "1.0.3"
shelf_static:
dependency: "direct main"
description:
name: shelf_static
sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e
url: "https://pub.dev"
source: hosted
version: "1.1.2"
shelf_web_socket:
dependency: "direct main"
description:
name: shelf_web_socket
sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1"
url: "https://pub.dev"
source: hosted
version: "1.0.4"
source_span:
dependency: transitive
description:
Expand All @@ -65,6 +145,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.10.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
url: "https://pub.dev"
source: hosted
version: "1.11.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
string_scanner:
dependency: transitive
description:
Expand All @@ -81,6 +177,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.1"
typed_data:
dependency: transitive
description:
name: typed_data
sha256: "26f87ade979c47a150c9eaab93ccd2bebe70a27dc0b4b29517f2904f04eb11a5"
url: "https://pub.dev"
source: hosted
version: "1.3.1"
web_socket_channel:
dependency: "direct main"
description:
name: web_socket_channel
sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b
url: "https://pub.dev"
source: hosted
version: "2.4.0"
yaml:
dependency: "direct main"
description:
Expand Down
5 changes: 5 additions & 0 deletions tools/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ dependencies:
args: ^2.4.1
intl: ^0.18.1
lints: ^2.0.1
shelf: ^1.4.1
shelf_proxy: ^1.0.3
shelf_static: ^1.1.2
shelf_web_socket: ^1.0.4
web_socket_channel: ^2.4.0
yaml: ^3.1.2

1 comment on commit 7bd01a0

@vercel
Copy link

@vercel vercel bot commented on 7bd01a0 May 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

qeck – ./app

qeck.vercel.app
qeck-git-develop-linwood.vercel.app
qeck-linwood.vercel.app

Please sign in to comment.