Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

Commit

Permalink
add post passthrough for proxy endpoint, add reboot endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
kclejeune committed Aug 31, 2021
1 parent eee9f09 commit 2c1d04b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export enum Endpoint {
STATUS = 'dashboard_device_info_status_web_app.cgi',
STATISTICS = 'statistics_status_web_app.cgi',
RADIO_CONFIG = 'fastmile_statistics_status_web_app.cgi',
REBOOT = 'reboot_web_app.cgi',
}

export interface DeviceAppStatus {
Expand Down
22 changes: 22 additions & 0 deletions src/routes/api/[endpoint].ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,25 @@ export async function get(request: ServerRequest): Promise<EndpointOutput> {
};
}
}

export async function post(request: ServerRequest): Promise<EndpointOutput> {
const endpoint = `${BASE_URL}/${request.params.endpoint}`;
const res = await fetch(endpoint, {
method: 'POST',
body: request.rawBody,
headers: { ...request.headers },
});
if (res.ok) {
const data = await res.json();
return {
body: data,
};
} else {
return {
status: res.status,
body: {
error: res.statusText,
},
};
}
}

0 comments on commit 2c1d04b

Please sign in to comment.