alemonjs 2.1.0-alpha.36 → 2.1.0-alpha.37
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/lib/cbp/hello.html.js +47 -0
- package/lib/cbp/router.js +6 -0
- package/lib/main.js +6 -3
- package/package.json +1 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const html = `
|
|
2
|
+
<!DOCTYPE html>
|
|
3
|
+
<html>
|
|
4
|
+
<head>
|
|
5
|
+
<title>欢迎使用 AlemonJS!</title>
|
|
6
|
+
<style>
|
|
7
|
+
body {
|
|
8
|
+
width: 35em;
|
|
9
|
+
margin: 0 auto;
|
|
10
|
+
font-family: Tahoma, Verdana, Arial, sans-serif;
|
|
11
|
+
background-color: #f8f8f8;
|
|
12
|
+
color: #333;
|
|
13
|
+
}
|
|
14
|
+
h1 {
|
|
15
|
+
color: #0099cc;
|
|
16
|
+
margin-top: 2em;
|
|
17
|
+
}
|
|
18
|
+
.footer {
|
|
19
|
+
margin-top: 3em;
|
|
20
|
+
font-size: 0.9em;
|
|
21
|
+
color: #888;
|
|
22
|
+
}
|
|
23
|
+
a {
|
|
24
|
+
color: #0099cc;
|
|
25
|
+
}
|
|
26
|
+
</style>
|
|
27
|
+
</head>
|
|
28
|
+
<body>
|
|
29
|
+
<h1>AlemonJS 启动成功!</h1>
|
|
30
|
+
<p>
|
|
31
|
+
恭喜,您的服务已成功通过 <a href="https://alemonjs.com" target="_blank">AlemonJS 框架</a> 启动。
|
|
32
|
+
</p>
|
|
33
|
+
<p>
|
|
34
|
+
如果想访问主应用,请访问, <a href="/app" target="_blank">/app</a>(对应根目录index.html)
|
|
35
|
+
</p>
|
|
36
|
+
<p>
|
|
37
|
+
如果想访问其他应用,请访问 /apps/[package-name]</a>。(对应/packages/[package-name]/index.html)
|
|
38
|
+
</p>
|
|
39
|
+
<div class="footer">
|
|
40
|
+
<p>感谢选择 AlemonJS。</p>
|
|
41
|
+
</div>
|
|
42
|
+
</body>
|
|
43
|
+
</html>
|
|
44
|
+
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
export { html };
|
package/lib/cbp/router.js
CHANGED
|
@@ -3,6 +3,7 @@ import fs, { existsSync } from 'fs';
|
|
|
3
3
|
import path, { join, dirname } from 'path';
|
|
4
4
|
import mime from 'mime-types';
|
|
5
5
|
import { createRequire } from 'module';
|
|
6
|
+
import { html } from './hello.html.js';
|
|
6
7
|
|
|
7
8
|
const require = createRequire(import.meta.url);
|
|
8
9
|
const mainDirMap = new Map();
|
|
@@ -45,6 +46,11 @@ const getModuelFile = (dir) => {
|
|
|
45
46
|
const router = new KoaRouter({
|
|
46
47
|
prefix: '/'
|
|
47
48
|
});
|
|
49
|
+
router.get('/', ctx => {
|
|
50
|
+
ctx.status = 200;
|
|
51
|
+
ctx.set('Content-Type', 'text/html; charset=utf-8');
|
|
52
|
+
ctx.body = html;
|
|
53
|
+
});
|
|
48
54
|
// 响应服务在线
|
|
49
55
|
router.get('api/online', ctx => {
|
|
50
56
|
ctx.status = 200;
|
package/lib/main.js
CHANGED
|
@@ -72,6 +72,7 @@ const start = async (options = {}) => {
|
|
|
72
72
|
const url = options?.url || cfg.argv?.url || cfg.value?.url;
|
|
73
73
|
// 连接到 CBP 服务器
|
|
74
74
|
if (url) {
|
|
75
|
+
logger.info(`[Connecting to CBP server at ${url}]`);
|
|
75
76
|
cbpClient(url);
|
|
76
77
|
}
|
|
77
78
|
else {
|
|
@@ -80,10 +81,12 @@ const start = async (options = {}) => {
|
|
|
80
81
|
// 设置环境变量
|
|
81
82
|
process.env.port = port;
|
|
82
83
|
cbpServer(port, async () => {
|
|
83
|
-
const
|
|
84
|
-
|
|
84
|
+
const httpURL = `http://127.0.0.1:${port}`;
|
|
85
|
+
const wsURL = `ws://127.0.0.1:${port}`;
|
|
86
|
+
logger.info(`[CBP server started at ${httpURL}]`);
|
|
87
|
+
logger.info(`[CBP server started at ${wsURL}]`);
|
|
85
88
|
const isFullReceive = options?.is_full_receive || cfg.argv?.is_full_receive || cfg.value?.is_full_receive || true;
|
|
86
|
-
cbpClient(
|
|
89
|
+
cbpClient(httpURL, { isFullReceive });
|
|
87
90
|
// 加载平台服务
|
|
88
91
|
const platform = options?.platform || cfg.argv?.platform || cfg.value?.platform;
|
|
89
92
|
const login = options?.login || cfg.argv?.login || cfg.value?.login;
|