Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
ha
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
ha
Commits
0549a047
Commit
0549a047
authored
Mar 20, 2024
by
Ahmad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parents
Pipeline
#193
canceled with stages
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
0 deletions
+74
-0
.gitignore
.idea/.gitignore
+5
-0
app.js
app.js
+54
-0
package.json
package.json
+15
-0
No files found.
.idea/.gitignore
0 → 100644
View file @
0549a047
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
app.js
0 → 100644
View file @
0549a047
const
axios
=
require
(
'
axios
'
);
const
fs
=
require
(
'
fs
'
).
promises
;
const
{
exec
}
=
require
(
'
child_process
'
);
const
util
=
require
(
'
util
'
);
const
execPromise
=
util
.
promisify
(
exec
);
const
BASE_URL
=
"
http://78.46.244.55:2020
"
;
const
CONFIG_PATH
=
'
/etc/haproxy/haproxy.cfg
'
;
async
function
run
()
{
try
{
const
data
=
await
getTunnel
();
const
config
=
data
.
config
;
await
processConfig
(
config
);
}
catch
(
error
)
{
console
.
error
(
error
);
}
}
async
function
processConfig
(
newConfig
)
{
try
{
const
currentConfig
=
await
fs
.
readFile
(
CONFIG_PATH
,
'
utf8
'
);
if
(
currentConfig
!==
newConfig
)
{
await
fs
.
writeFile
(
CONFIG_PATH
,
newConfig
);
await
reloadHAProxy
();
}
}
catch
(
error
)
{
throw
error
;
}
}
async
function
reloadHAProxy
()
{
try
{
const
{
stdout
,
stderr
}
=
await
execPromise
(
'
sudo systemctl reload haproxy
'
);
console
.
log
(
'
HAProxy reloaded successfully:
'
,
stdout
);
if
(
stderr
)
{
console
.
error
(
'
Reload error:
'
,
stderr
);
}
}
catch
(
error
)
{
throw
error
;
}
}
async
function
getTunnel
()
{
try
{
const
response
=
await
axios
.
get
(
`
${
BASE_URL
}
/getTunnel`
,
{
timeout
:
3000
});
return
response
.
data
;
}
catch
(
error
)
{
throw
'
Error fetching tunnel configuration
'
;
}
}
run
();
package.json
0 → 100644
View file @
0549a047
{
"name"
:
"ha"
,
"version"
:
"1.0.0"
,
"description"
:
""
,
"main"
:
"index.js"
,
"scripts"
:
{
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
},
"keywords"
:
[],
"author"
:
""
,
"license"
:
"
ISC
"
,
"dependencies"
:
{
"
axios
"
:
"
^1.6.8
"
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment