alemonjs 2.1.0-alpha.35 → 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.
@@ -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;
@@ -102,7 +108,7 @@ router.all('app/{*path}', async (ctx) => {
102
108
  };
103
109
  return;
104
110
  }
105
- const apiModule = await import(modulePath);
111
+ const apiModule = await import(`file://${modulePath}`);
106
112
  if (!apiModule[ctx.method] || typeof apiModule[ctx.method] !== 'function') {
107
113
  ctx.status = 405;
108
114
  return;
@@ -216,7 +222,7 @@ router.all('apps/:app/{*path}', async (ctx) => {
216
222
  };
217
223
  return;
218
224
  }
219
- const apiModule = await import(modulePath);
225
+ const apiModule = await import(`file://${modulePath}`);
220
226
  if (!apiModule[ctx.method] || typeof apiModule[ctx.method] !== 'function') {
221
227
  ctx.status = 405;
222
228
  return;
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 url = `ws://127.0.0.1:${port}`;
84
- logger.info(`[CBP server started at ${url}]`);
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(url, { isFullReceive });
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "2.1.0-alpha.35",
3
+ "version": "2.1.0-alpha.37",
4
4
  "description": "bot script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",