diff options
| author | Li Zhineng <[email protected]> | 2025-07-02 20:35:37 +0800 |
|---|---|---|
| committer | Li Zhineng <[email protected]> | 2025-07-02 20:35:37 +0800 |
| commit | 4abaac6c5df21a68d1ace7bcaee1e016a9edd90f (patch) | |
| tree | 953e0f0f4fe5bf288d0261ddbff38209a0d12d75 | |
| parent | a3b6429c4818f2688a04e78a55954abf1993feb8 (diff) | |
| download | server-4abaac6c5df21a68d1ace7bcaee1e016a9edd90f.tar.gz server-4abaac6c5df21a68d1ace7bcaee1e016a9edd90f.zip | |
subprocedure by path name
| -rw-r--r-- | server.mjs | 14 | ||||
| -rw-r--r-- | server.test.mjs | 6 |
2 files changed, 20 insertions, 0 deletions
@@ -30,6 +30,20 @@ const getTimeControlller = (req, res) => { const eagleController = (req, res) => { const [, query] = req.url.split('?') const params = new URLSearchParams(query) + + switch (params.get('path')) { + case 'eagle/GET/genId': + eagleGenIdController(req, res) + break + default: + notFoundController(req, res) + break + } +} + +const eagleGenIdController = (req, res) => { + const [, query] = req.url.split('?') + const params = new URLSearchParams(query) const { mac, key } = JSON.parse(params.get('params') || '{}') if (mac === undefined || key === undefined) { diff --git a/server.test.mjs b/server.test.mjs index 259b913..1e44083 100644 --- a/server.test.mjs +++ b/server.test.mjs @@ -136,6 +136,12 @@ test('device registration endpoint returns bad request if missing encryption key assert.strictEqual(res.headers.get('content-type'), 'application/json') }) +test('device registration endpoint returns not found if path is not supported', async () => { + const params = new URLSearchParams({ path: 'eagle/GET/foo' }) + const res = await fetch(`${baseUrl}/eagle?${params.toString()}`) + assert.strictEqual(res.status, 404) +}) + test('exchange endpoint', async () => { const stubMacAddress = '0000000000' const stubKey = '00000000000000000000000000000000' |
