update
This commit is contained in:
4
src/apps/ai/app.ts
Normal file
4
src/apps/ai/app.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { QueryRouterServer } from '@kevisual/router/browser'
|
||||
import { useContextKey } from '@kevisual/context'
|
||||
const app = useContextKey('app', new QueryRouterServer())
|
||||
export { app }
|
||||
6
src/apps/ai/index.ts
Normal file
6
src/apps/ai/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { app } from './app'
|
||||
|
||||
import './routes/login'
|
||||
|
||||
|
||||
export { app }
|
||||
14
src/apps/ai/routes/login/index.ts
Normal file
14
src/apps/ai/routes/login/index.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { app } from '../../app'
|
||||
|
||||
app.route({
|
||||
path: 'login',
|
||||
description: '登录应用,参数 username 是用户名,password 是密码',
|
||||
|
||||
}).define(async (ctx) => {
|
||||
const { username, password } = ctx.query;
|
||||
|
||||
ctx.body = {
|
||||
message: `User ${username} logged in successfully.`,
|
||||
}
|
||||
}
|
||||
).addTo(app)
|
||||
42
src/apps/web-command/index.tsx
Normal file
42
src/apps/web-command/index.tsx
Normal file
@@ -0,0 +1,42 @@
|
||||
import { app } from '../ai';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
const getAppRoutes = () => {
|
||||
const appRoutes = app.routes.map((route) => {
|
||||
return {
|
||||
path: route.path,
|
||||
key: route.key,
|
||||
description: route.description,
|
||||
metadata: route.metadata,
|
||||
}
|
||||
});
|
||||
return appRoutes;
|
||||
}
|
||||
|
||||
const fetchTest = async () => {
|
||||
const url = 'http://localhost:51015/api/router';
|
||||
const response = await fetch(url);
|
||||
const data = await response.json();
|
||||
console.log('Fetch Test Data:', data);
|
||||
}
|
||||
const dynamicImport = async () => {
|
||||
const module = await import('http://localhost:4321/test-import.js');
|
||||
console.log('Dynamically Imported Module:', module);
|
||||
console.log('Test Function Output:', module.test());
|
||||
|
||||
}
|
||||
export const App = () => {
|
||||
const [appRoutes, setAppRoutes] = useState(getAppRoutes());
|
||||
useEffect(() => {
|
||||
setAppRoutes(getAppRoutes());
|
||||
}, []);
|
||||
return <div>Web Command App
|
||||
|
||||
<pre onClick={async () => {
|
||||
|
||||
await dynamicImport()
|
||||
setAppRoutes(getAppRoutes());
|
||||
}
|
||||
}>{JSON.stringify(appRoutes, null, 2)}</pre>
|
||||
</div >;
|
||||
}
|
||||
Reference in New Issue
Block a user