-
-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added remote-control server code and template
- Loading branch information
Showing
7 changed files
with
168 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ preload.js | |
shared/*.js | ||
playwright-report | ||
.nx | ||
server.js | ||
|
||
# dependencies | ||
/node_modules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<html> | ||
<head> | ||
<title>{{it.title}}</title> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} | ||
header { | ||
width: 100%; | ||
background-color: #f8f9fa; | ||
padding: 10px 0; | ||
text-align: center; | ||
} | ||
header h1 { | ||
margin: 0; | ||
font-size: 24px; | ||
} | ||
.button-container { | ||
display: flex; | ||
justify-content: center; | ||
gap: 20px; | ||
margin-top: 20px; | ||
} | ||
button { | ||
padding: 10px 20px; | ||
border: none; | ||
border-radius: 5px; | ||
font-size: 16px; | ||
cursor: pointer; | ||
color: white; | ||
} | ||
.up-channel { | ||
background-color: #007bff; | ||
} | ||
.down-channel { | ||
background-color: #28a745; | ||
} | ||
footer { | ||
margin-top: 30px; | ||
text-align: center; | ||
} | ||
footer p { | ||
font-size: 14px; | ||
color: #6c757d; | ||
} | ||
</style> | ||
<script> | ||
// AJAX isteği yapmak için fetch API kullanımı | ||
function callAjax(url) { | ||
fetch(url) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error('Network response was not ok'); | ||
} | ||
return response.json(); | ||
}) | ||
.then(data => { | ||
console.log('Success:', data); | ||
alert('AJAX request successful! Check console for data.'); | ||
}) | ||
.catch((error) => { | ||
console.error('There was a problem with your fetch operation:', error); | ||
}); | ||
} | ||
</script> | ||
</head> | ||
<body> | ||
<header> | ||
<h1>{{it.headerText}}</h1> | ||
</header> | ||
|
||
<div class="button-container"> | ||
<button class="up-channel" onclick="callAjax('{{it.upChannelUrl}}')">{{it.upChannelText}}</button> | ||
<button class="down-channel" onclick="callAjax('{{it.downChannelUrl}}')">{{it.downChannelText}}</button> | ||
</div> | ||
|
||
<footer> | ||
<p>{{it.footer}}</p> | ||
</footer> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { IncomingMessage, ServerResponse } from "http"; | ||
|
||
const http = require('http'); | ||
const Sqrl = require('squirrelly'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
export class Server { | ||
/** Server instance */ | ||
server: any; | ||
/** Port number */ | ||
port: number; | ||
/** Api instance */ | ||
api: any; | ||
|
||
/** | ||
* Creates a new server instance | ||
* @param port port number | ||
* @param api application instance | ||
*/ | ||
constructor(_port: number, _api: any) { | ||
this.api = _api; | ||
this.port = _port; | ||
this.server = http.createServer(this.requestListener.bind(this)); | ||
this.server.listen(this.port); | ||
} | ||
|
||
async requestListener(request: IncomingMessage, response: ServerResponse) { | ||
const currentPage = request.url?.split('?')[0]?.split('/').splice(-1)[0]; | ||
console.log(this.api.store); | ||
switch (currentPage) { | ||
case '': { | ||
const indexFile = await fs.promises.readFile(path.join(__dirname, './remote-control/', 'index.sqrl'), 'utf-8'); | ||
const renderedHtml = Sqrl.render(indexFile, { | ||
headerText: 'My Dynamic Header', | ||
upChannelText: 'Up Channel', | ||
downChannelText: 'Down Channel', | ||
upChannelUrl: '/upChannel', | ||
downChannelUrl: '/downChannel', | ||
title: 'IPTVNator' | ||
}); | ||
response.writeHead(200, { 'Content-Type': 'text/html' }); | ||
response.end(renderedHtml); | ||
break; | ||
} | ||
case 'upChannel': { | ||
// this.api.upChannel(); | ||
response.writeHead(200, { 'Content-Type': 'text/html' }); | ||
response.end('Up Channel'); | ||
break; | ||
} | ||
default: | ||
response.writeHead(404, { 'Content-Type': 'text/html' }); | ||
response.end('404'); | ||
break; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters