feat(sae): add Java MVP backend and Taobao connectivity page
Spring Boot 3.5.6 / Java 17 JAR with cloud gateway envelope and ping/whoami/echo; Taobao gateway signature verification matching the Node implementation; /pages/mvp page, splash dev entry and local transport contract test; SAE + 聚石塔 runbook and portable JDK/Maven setup; Windows 11 wmic shim for Taobao DevTools.
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
'use strict';
|
||||
|
||||
// 不依赖淘宝 IDE 的本地契约测试:
|
||||
// 用 Node 模拟 my.request,加载真实的 utils/transport.js,直连 Java 后端。
|
||||
// 运行前先启动 backend-java,然后:node scripts/mvp-local-check.cjs
|
||||
|
||||
const http = require('node:http');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const vm = require('node:vm');
|
||||
const assert = require('node:assert/strict');
|
||||
|
||||
const BASE = process.env.MVP_BASE_URL || 'http://127.0.0.1:8080';
|
||||
const config = {
|
||||
environment: 'development',
|
||||
transport: 'direct',
|
||||
baseUrl: BASE,
|
||||
assetBase: BASE + '/assets/',
|
||||
cloudAppId: '',
|
||||
cloudEnv: 'test',
|
||||
basePath: '',
|
||||
mock: false
|
||||
};
|
||||
|
||||
function httpRequest(url, options, body) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = http.request(url, options, (res) => {
|
||||
const chunks = [];
|
||||
res.on('data', (chunk) => chunks.push(chunk));
|
||||
res.on('end', () => {
|
||||
const text = Buffer.concat(chunks).toString('utf8');
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(text);
|
||||
} catch (e) {
|
||||
reject(new Error('non-JSON response: ' + text.slice(0, 200)));
|
||||
return;
|
||||
}
|
||||
resolve({ status: res.statusCode, statusCode: res.statusCode, data });
|
||||
});
|
||||
});
|
||||
req.on('error', reject);
|
||||
req.end(body);
|
||||
});
|
||||
}
|
||||
|
||||
const my = {
|
||||
request(options) {
|
||||
httpRequest(options.url, { method: options.method, headers: options.headers }, options.data)
|
||||
.then((res) => options.success(res))
|
||||
.catch((err) => options.fail(err));
|
||||
}
|
||||
};
|
||||
|
||||
const transportModule = { exports: {} };
|
||||
vm.runInNewContext(fs.readFileSync(path.join(__dirname, '../utils/transport.js'), 'utf8'), {
|
||||
module: transportModule,
|
||||
Promise,
|
||||
my,
|
||||
require(name) {
|
||||
return name === '../config' ? config : {};
|
||||
}
|
||||
});
|
||||
|
||||
const transport = transportModule.exports;
|
||||
|
||||
(async () => {
|
||||
const ping = await transport.request('/api/taobao/ping', {});
|
||||
assert.equal(ping.server, 'java', 'ping.server should be java');
|
||||
assert.equal(ping.pong, true, 'ping.pong should be true');
|
||||
|
||||
const echo = await transport.request('/api/taobao/echo', { hello: 'mvp' });
|
||||
assert.equal(echo.body.hello, 'mvp', 'echo.body.hello should round-trip');
|
||||
|
||||
const whoami = await transport.request('/api/taobao/whoami', {});
|
||||
assert.equal(whoami.ok, true, 'whoami.ok should be true');
|
||||
|
||||
console.log('PASS');
|
||||
console.log(JSON.stringify({ ping, echo, whoami }, null, 2));
|
||||
})().catch((err) => {
|
||||
console.error('FAIL:', err && err.stack ? err.stack : err);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user