Skip to content

Commit 076c2fe

Browse files
committed
fixing the error related to serverapi
1 parent ee02098 commit 076c2fe

File tree

2 files changed

+40
-29
lines changed

2 files changed

+40
-29
lines changed

cleanup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { shutdown } = require('./serverapi');
1+
const { shutdown } = require('./src/utils/serverAPI'); // Use CommonJS `require` syntax
22
const isWindows = process.platform === 'win32';
33

44
const kill = async (process) => {

src/utils/serverAPI.js

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,47 @@
11
const config = require('../../rpe.config.json');
2-
32
const { server } = config;
43
let { port } = config;
54

6-
export function devices() {
5+
function devices() {
76
return `${server}:${port}/devices`;
87
}
98

10-
export function attributes() {
9+
function attributes() {
1110
return `${server}:${port}/attributes`;
1211
}
1312

14-
export function project() {
13+
function project() {
1514
return `${server}:${port}/project`;
1615
}
1716

18-
export function projectClose() {
17+
function projectClose() {
1918
return `${project()}/close`;
2019
}
2120

22-
export function projectOpen() {
21+
function projectOpen() {
2322
return `${project()}/open`;
2423
}
2524

26-
export function projectSave() {
25+
function projectSave() {
2726
return `${project()}/create`;
2827
}
2928

30-
export function setPort(p, fetchDevices) {
29+
function setPort(p, fetchDevices) {
3130
if (p !== undefined) {
3231
port = p;
3332
GET(devices(), fetchDevices);
3433
}
3534
}
3635

37-
export function peripheralPath(deviceId, url) {
36+
function peripheralPath(deviceId, url) {
3837
return `${devices()}/${deviceId}/peripherals/${url}`;
3938
}
4039

41-
export function deviceInfo(deviceId) {
40+
function deviceInfo(deviceId) {
4241
return `${devices()}/${deviceId}`;
4342
}
4443

45-
export const Elem = {
44+
const Elem = {
4645
clocking: 'clocking',
4746
io: 'io',
4847
bram: 'bram',
@@ -51,7 +50,7 @@ export const Elem = {
5150
peripherals: 'peripherals',
5251
};
5352

54-
export const api = {
53+
const api = {
5554
fetch(func, deviceId) {
5655
return `${devices()}/${deviceId}/${func}`;
5756
},
@@ -65,43 +64,35 @@ export const api = {
6564
},
6665
};
6766

68-
export function POST(url, data, callback) {
67+
function POST(url, data, callback) {
6968
fetch(url, {
7069
method: 'POST',
7170
headers: { 'Content-Type': 'application/json' },
7271
body: JSON.stringify(data),
7372
}).then((response) => {
74-
if (response.ok) {
75-
if (callback) callback();
76-
}
73+
if (response.ok && callback) callback();
7774
});
7875
}
7976

80-
export function DELETE(url, callback) {
77+
function DELETE(url, callback) {
8178
fetch(url, {
8279
method: 'DELETE',
8380
}).then((response) => {
84-
if (response.ok) {
85-
if (callback) callback();
86-
}
81+
if (response.ok && callback) callback();
8782
});
8883
}
8984

90-
export function PATCH(url, data, callback) {
85+
function PATCH(url, data, callback) {
9186
fetch(url, {
9287
method: 'PATCH',
9388
headers: { 'Content-Type': 'application/json' },
9489
body: JSON.stringify(data),
9590
}).then((response) => {
96-
if (response.ok) {
97-
if (callback) callback();
98-
} else {
99-
// TODO: handle error
100-
}
91+
if (response.ok && callback) callback();
10192
});
10293
}
10394

104-
export function GET(url, callback) {
95+
function GET(url, callback) {
10596
fetch(url)
10697
.then((response) => response.json())
10798
.then((data) => {
@@ -110,7 +101,27 @@ export function GET(url, callback) {
110101
}
111102

112103
// Function to call the shutdown API
113-
export function shutdown(callback) {
104+
function shutdown(callback) {
114105
const shutdownUrl = `${server}:${port}/shutdown`;
115106
POST(shutdownUrl, null, callback);
116107
}
108+
109+
// Exporting functions using CommonJS syntax
110+
module.exports = {
111+
devices,
112+
attributes,
113+
project,
114+
projectClose,
115+
projectOpen,
116+
projectSave,
117+
setPort,
118+
peripheralPath,
119+
deviceInfo,
120+
Elem,
121+
api,
122+
POST,
123+
DELETE,
124+
PATCH,
125+
GET,
126+
shutdown,
127+
};

0 commit comments

Comments
 (0)