@mindw1n/webnative 3.0.4 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +19 -19
- package/package.json +2 -2
- package/prebuilds/dist/linux +0 -0
- package/template/js/app/api/android.js +4 -0
- package/template/js/app/api/ios.js +4 -0
- package/template/js/app/api/linux.js +23 -0
- package/template/js/app/api/macos.js +4 -0
- package/template/js/app/api/windows.js +4 -0
- package/template/js/app/backend/index.js +36 -1
- package/template/js/app/index.js +4 -1
- package/template/js/app/public/index.css +12 -3
- package/template/js/app/public/index.html +1 -0
- package/template/js/webnative.json +7 -2
- package/template/js/webpack.config.js +1 -0
- package/template/ts/app/api/android.ts +4 -0
- package/template/ts/app/api/index.d.ts +1 -0
- package/template/ts/app/api/ios.ts +4 -0
- package/template/ts/app/api/linux.ts +23 -0
- package/template/ts/app/api/macos.ts +4 -0
- package/template/ts/app/api/windows.ts +4 -0
- package/template/ts/app/backend/index.ts +36 -1
- package/template/ts/app/index.ts +4 -1
- package/template/ts/app/public/index.css +12 -3
- package/template/ts/app/public/index.html +1 -0
- package/template/ts/webnative.json +7 -2
- package/template/ts/webpack.config.js +1 -0
- package/prebuilds/dist/linux_self_contained +0 -0
- package/template/js/app/public/index.js +0 -6
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mindw1n/webnative",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0
|
|
4
|
+
"version": "3.1.0",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "esbuild src/index.ts --bundle --platform=node --format=esm --target=es2020 --outfile=index.js --banner:js=\"#!/usr/bin/env node\" --minify"
|
|
7
7
|
},
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
],
|
|
19
19
|
"keywords": [],
|
|
20
20
|
"author": "",
|
|
21
|
-
"license": "
|
|
21
|
+
"license": "MIT",
|
|
22
22
|
"description": "",
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@eslint/js": "^9.39.2",
|
package/prebuilds/dist/linux
CHANGED
|
Binary file
|
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
import { authenticate } from "@mindw1n/webnative-core/linux/api/authenticate";
|
|
2
|
+
|
|
1
3
|
export function getPlatform() {
|
|
2
4
|
return "Linux";
|
|
3
5
|
}
|
|
6
|
+
|
|
7
|
+
export async function getBackendStatus() {
|
|
8
|
+
try {
|
|
9
|
+
const data = await authenticate();
|
|
10
|
+
|
|
11
|
+
const response = await fetch(`http://127.0.0.1:${data.port}`, {
|
|
12
|
+
method: "GET",
|
|
13
|
+
headers: {
|
|
14
|
+
"X-API-Key": data.key,
|
|
15
|
+
"Content-Type": "application/json"
|
|
16
|
+
}
|
|
17
|
+
}).then((res) => res.json());
|
|
18
|
+
|
|
19
|
+
if (response.error) return "unauthorized";
|
|
20
|
+
|
|
21
|
+
return "online";
|
|
22
|
+
} catch (e) {
|
|
23
|
+
console.error(e);
|
|
24
|
+
return "offline";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -1 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
import { createWriteStream } from "fs";
|
|
2
|
+
import { randomBytes, timingSafeEqual } from "crypto";
|
|
3
|
+
import express from "express";
|
|
4
|
+
import cors from "cors";
|
|
5
|
+
|
|
6
|
+
const pipe = createWriteStream("", { fd: Number(process.argv[2]) });
|
|
7
|
+
const key = randomBytes(32).toString("hex");
|
|
8
|
+
|
|
9
|
+
const app = express();
|
|
10
|
+
app.use(cors());
|
|
11
|
+
app.use(express.json());
|
|
12
|
+
|
|
13
|
+
app.use((req, res) => {
|
|
14
|
+
const key = req.headers["x-api-key"];
|
|
15
|
+
|
|
16
|
+
if (typeof key !== "string" || !checkKey(key)) {
|
|
17
|
+
console.log("Unauthorized: " + req.url);
|
|
18
|
+
return res.status(401).json({ error: "Unauthorized" });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
console.log(`Request authorized: ${req.url}`);
|
|
22
|
+
return res.status(200).json({ status: "authorized" });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const server = app.listen(0, "127.0.0.1", () => {
|
|
26
|
+
const port = server.address().port;
|
|
27
|
+
console.log("Serving on port " + port);
|
|
28
|
+
pipe.write(JSON.stringify({ port, key }) + "\0");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
function checkKey(incoming) {
|
|
32
|
+
const a = Buffer.from(incoming);
|
|
33
|
+
const b = Buffer.from(key);
|
|
34
|
+
if (a.length !== b.length) return false;
|
|
35
|
+
return timingSafeEqual(a, b);
|
|
36
|
+
}
|
package/template/js/app/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { getPlatform } from "./api";
|
|
1
|
+
import { getBackendStatus, getPlatform, } from "./api";
|
|
2
2
|
|
|
3
3
|
const platform = document.getElementById("platform");
|
|
4
4
|
if (platform) platform.textContent = getPlatform();
|
|
5
|
+
|
|
6
|
+
const backendStatus = document.getElementById("backend-status");
|
|
7
|
+
if (backendStatus) backendStatus.textContent = await getBackendStatus();
|
|
@@ -55,9 +55,18 @@ h2 {
|
|
|
55
55
|
right: 24px;
|
|
56
56
|
font-size: 20px;
|
|
57
57
|
font-weight: 400;
|
|
58
|
-
color: #
|
|
58
|
+
color: #707089;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
span {
|
|
62
62
|
color: #7c6fff;
|
|
63
|
-
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.backend-status {
|
|
66
|
+
position: fixed;
|
|
67
|
+
bottom: 20px;
|
|
68
|
+
left: 24px;
|
|
69
|
+
font-size: 20px;
|
|
70
|
+
font-weight: 400;
|
|
71
|
+
color: #707089;
|
|
72
|
+
}
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
<h1>Your webnative app,<br><span>Build web. Ship anywhere.</span></h1>
|
|
13
13
|
<p>Deliver your application to every platform with just one codebase</p>
|
|
14
14
|
<h2>Currently runs on <span id="platform"></span></h2>
|
|
15
|
+
<h3 class="backend-status">Backend status: <span id="backend-status"></span></h3>
|
|
15
16
|
</div>
|
|
16
17
|
<script src="./index.js"></script>
|
|
17
18
|
</body>
|
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
import { authenticate } from "@mindw1n/webnative-core/linux/api/authenticate";
|
|
2
|
+
|
|
1
3
|
export function getPlatform() {
|
|
2
4
|
return "Linux";
|
|
3
5
|
}
|
|
6
|
+
|
|
7
|
+
export async function getBackendStatus() {
|
|
8
|
+
try {
|
|
9
|
+
const data = await authenticate();
|
|
10
|
+
|
|
11
|
+
const response = await fetch(`http://127.0.0.1:${data.port}`, {
|
|
12
|
+
method: "GET",
|
|
13
|
+
headers: {
|
|
14
|
+
"X-API-Key": data.key,
|
|
15
|
+
"Content-Type": "application/json"
|
|
16
|
+
}
|
|
17
|
+
}).then((res) => res.json());
|
|
18
|
+
|
|
19
|
+
if (response.error) return "unauthorized";
|
|
20
|
+
|
|
21
|
+
return "online";
|
|
22
|
+
} catch (e) {
|
|
23
|
+
console.error(e);
|
|
24
|
+
return "offline";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -1 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
import { createWriteStream } from "fs";
|
|
2
|
+
import { randomBytes, timingSafeEqual } from "crypto";
|
|
3
|
+
import express from "express";
|
|
4
|
+
import cors from "cors";
|
|
5
|
+
|
|
6
|
+
const pipe = createWriteStream("", { fd: Number(process.argv[2]) });
|
|
7
|
+
const key = randomBytes(32).toString("hex");
|
|
8
|
+
|
|
9
|
+
const app = express();
|
|
10
|
+
app.use(cors());
|
|
11
|
+
app.use(express.json());
|
|
12
|
+
|
|
13
|
+
app.use((req, res) => {
|
|
14
|
+
const key = req.headers["x-api-key"];
|
|
15
|
+
|
|
16
|
+
if (typeof key !== "string" || !checkKey(key)) {
|
|
17
|
+
console.log("Unauthorized: " + req.url);
|
|
18
|
+
return res.status(401).json({ error: "Unauthorized" });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
console.log(`Request authorized: ${req.url}`);
|
|
22
|
+
return res.status(200).json({ status: "authorized" });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const server = app.listen(0, "127.0.0.1", () => {
|
|
26
|
+
const port = (server.address() as { port: number }).port;
|
|
27
|
+
console.log("Serving on port " + port);
|
|
28
|
+
pipe.write(JSON.stringify({ port, key }) + "\0");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
function checkKey(incoming: string): boolean {
|
|
32
|
+
const a = Buffer.from(incoming);
|
|
33
|
+
const b = Buffer.from(key);
|
|
34
|
+
if (a.length !== b.length) return false;
|
|
35
|
+
return timingSafeEqual(a, b);
|
|
36
|
+
}
|
package/template/ts/app/index.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { getPlatform } from "./api";
|
|
1
|
+
import { getBackendStatus, getPlatform } from "./api";
|
|
2
2
|
|
|
3
3
|
const platform = document.getElementById("platform");
|
|
4
4
|
if (platform) platform.textContent = getPlatform();
|
|
5
|
+
|
|
6
|
+
const backendStatus = document.getElementById("backend-status");
|
|
7
|
+
if (backendStatus) backendStatus.textContent = await getBackendStatus();
|
|
@@ -55,9 +55,18 @@ h2 {
|
|
|
55
55
|
right: 24px;
|
|
56
56
|
font-size: 20px;
|
|
57
57
|
font-weight: 400;
|
|
58
|
-
color: #
|
|
58
|
+
color: #707089;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
span {
|
|
62
62
|
color: #7c6fff;
|
|
63
|
-
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.backend-status {
|
|
66
|
+
position: fixed;
|
|
67
|
+
bottom: 20px;
|
|
68
|
+
left: 24px;
|
|
69
|
+
font-size: 20px;
|
|
70
|
+
font-weight: 400;
|
|
71
|
+
color: #707089;
|
|
72
|
+
}
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
<h1>Your webnative app,<br><span>Build web. Ship anywhere.</span></h1>
|
|
13
13
|
<p>Deliver your application to every platform with just one codebase</p>
|
|
14
14
|
<h2>Currently runs on <span id="platform"></span></h2>
|
|
15
|
+
<h3 class="backend-status">Backend status: <span id="backend-status"></span></h3>
|
|
15
16
|
</div>
|
|
16
17
|
<script src="./index.js"></script>
|
|
17
18
|
</body>
|
|
Binary file
|