mirror of
https://github.com/JustKato/FreePad.git
synced 2026-03-18 18:19:46 +02:00
Compare commits
21 Commits
1b1fe59877
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 3a6c796cac | |||
| 6376fa9128 | |||
| ca10033ecf | |||
| b68e5c8e88 | |||
| 84ccd44fd7 | |||
| 0a1bff5cd4 | |||
| 7982d564e8 | |||
| becbf30752 | |||
| 796a3b07c4 | |||
| 5518103575 | |||
| 177ab62720 | |||
| 5a8ccf20a8 | |||
| a71be11135 | |||
| 30dc23c847 | |||
| 0a3b5d50f2 | |||
| b4c47ded35 | |||
| 6e401a416f | |||
| 3b137c5ed6 | |||
| c4f6496e0e | |||
| ee9516a109 | |||
| 7dcad9dc31 |
23
README.md
23
README.md
@@ -19,6 +19,29 @@ The project is absolutely free to use, you can extend the code and even contribu
|
|||||||
|
|
||||||
The current maintainer and creator is `Kato Twofold`
|
The current maintainer and creator is `Kato Twofold`
|
||||||
|
|
||||||
|
# 🛑 About reverse proxying 🛑
|
||||||
|
If you are looking to reverse proxy this program, please keep in mind that the websockets have specific settings regarding reverse proxying, I have tried using `Apache2` but to no luck, if someone could give a suggestion as to how to set up my own program on `Apache2` it'd be amazing.
|
||||||
|
On `Nginx` it's rather simple, here is my reverse proxy for the demo at [pad.justkato.me](https://pad.justkato.me/)
|
||||||
|
```nginx
|
||||||
|
server {
|
||||||
|
# Define the basic information such as server name and log location
|
||||||
|
server_name pad.justkato.me
|
||||||
|
access_log logs/pad.justkato.me.access.log main;
|
||||||
|
|
||||||
|
# setup the reverse proxy
|
||||||
|
location / {
|
||||||
|
proxy_pass http://127.0.0.1:1626;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
|
||||||
|
# WebSocket support !! Important !!
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/JustKato/FreePad/lib/objects"
|
"github.com/JustKato/FreePad/lib/objects"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -34,13 +33,14 @@ func BindSocket(router *gin.RouterGroup) {
|
|||||||
// Get the name of the pad to assign to this socket
|
// Get the name of the pad to assign to this socket
|
||||||
padName := ctx.Param("pad")
|
padName := ctx.Param("pad")
|
||||||
// Upgrade the socket connection
|
// Upgrade the socket connection
|
||||||
webSocketUpgrade(ctx.Writer, ctx.Request, padName)
|
webSocketUpgrade(ctx, padName)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func webSocketUpgrade(w http.ResponseWriter, r *http.Request, padName string) {
|
func webSocketUpgrade(ctx *gin.Context, padName string) {
|
||||||
conn, err := wsUpgrader.Upgrade(w, r, nil)
|
|
||||||
|
conn, err := wsUpgrader.Upgrade(ctx.Writer, ctx.Request, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to set websocket upgrade: %v\n", err)
|
fmt.Printf("Failed to set websocket upgrade: %v\n", err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -45,6 +45,24 @@ main#main-card {
|
|||||||
tab-size: 2;
|
tab-size: 2;
|
||||||
|
|
||||||
font-family: 'Roboto Mono', monospace !important;
|
font-family: 'Roboto Mono', monospace !important;
|
||||||
|
|
||||||
|
padding-top: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
#padTitle {
|
||||||
|
padding: .3rem .75rem !important;
|
||||||
|
border-radius: .25rem;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark #padTitle {
|
||||||
|
color: #db3384;
|
||||||
|
background-color: rgba(0, 0, 0, 0.10);
|
||||||
|
}
|
||||||
|
|
||||||
|
.light #padTitle {
|
||||||
|
color: #555273;
|
||||||
|
border: 1px solid rgba(0, 0, 0, 0.15);
|
||||||
}
|
}
|
||||||
|
|
||||||
#pad-content-area {
|
#pad-content-area {
|
||||||
@@ -54,11 +72,16 @@ main#main-card {
|
|||||||
flex-flow: column;
|
flex-flow: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.light .edit-content-text {
|
||||||
|
color: white !important;
|
||||||
|
}
|
||||||
|
|
||||||
.edit-content-text {
|
.edit-content-text {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.read-only-content .edit-content-text {
|
.read-only-content .edit-content-text {
|
||||||
|
margin-top: 1rem;
|
||||||
display: block !important;
|
display: block !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,6 +101,9 @@ main#main-card {
|
|||||||
max-height: calc(17rem + 30vh);
|
max-height: calc(17rem + 30vh);
|
||||||
min-height: 17rem;
|
min-height: 17rem;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
|
|
||||||
|
padding-top: 2rem;
|
||||||
|
margin-top: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
textarea:focus,
|
textarea:focus,
|
||||||
|
|||||||
@@ -138,7 +138,10 @@ function renderArchivesSelection() {
|
|||||||
let resp = confirm("Load contents of pad from memory? This will overwrite the current pad for everyone.");
|
let resp = confirm("Load contents of pad from memory? This will overwrite the current pad for everyone.");
|
||||||
|
|
||||||
if (!!resp) {
|
if (!!resp) {
|
||||||
document.getElementById(`pad-content`).value = a.content;
|
// Update visually for the client
|
||||||
|
updatePadContent(a.content);
|
||||||
|
// Send the update
|
||||||
|
window.socket.sendPadUpdate();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -210,6 +213,8 @@ function setTextareaPreview(t = true) {
|
|||||||
|
|
||||||
padContentArea.classList.add(`read-only-content`);
|
padContentArea.classList.add(`read-only-content`);
|
||||||
|
|
||||||
|
prev.scrollTop = prev.scrollHeight;
|
||||||
|
|
||||||
textarea.classList.add(`hidden`);
|
textarea.classList.add(`hidden`);
|
||||||
} else {
|
} else {
|
||||||
// Toggle edit mode
|
// Toggle edit mode
|
||||||
|
|||||||
@@ -31,8 +31,14 @@ class PadSocket {
|
|||||||
|
|
||||||
// Check if a connection URL was mentioned
|
// Check if a connection URL was mentioned
|
||||||
if ( connUrl == null ) {
|
if ( connUrl == null ) {
|
||||||
|
|
||||||
|
let connProtocol = `ws://`;
|
||||||
|
if ( window.location.protocol == `https:` ) {
|
||||||
|
connProtocol = `wss://`;
|
||||||
|
}
|
||||||
|
|
||||||
// Try and connect to the local websocket
|
// Try and connect to the local websocket
|
||||||
connUrl = `ws://` + window.location.host + `/ws/get/${padName}`;
|
connUrl = connProtocol + window.location.host + `/ws/get/${padName}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect to the websocket
|
// Connect to the websocket
|
||||||
@@ -45,9 +51,13 @@ class PadSocket {
|
|||||||
updateStatus(`Established`, `text-success`);
|
updateStatus(`Established`, `text-success`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onFail() {
|
||||||
|
updateStatus(`Connection Failed`, `text-dangerous`);
|
||||||
|
}
|
||||||
|
|
||||||
// Try and reconnect on failure
|
// Try and reconnect on failure
|
||||||
ws.onclose = connectSocket;
|
ws.onclose = onFail;
|
||||||
ws.onerror = connectSocket;
|
ws.onerror = onFail;
|
||||||
|
|
||||||
// Assign the websocket
|
// Assign the websocket
|
||||||
this.ws = ws;
|
this.ws = ws;
|
||||||
@@ -176,10 +186,34 @@ class PadSocket {
|
|||||||
*/
|
*/
|
||||||
function updatePadContent(newContent, textArea = true) {
|
function updatePadContent(newContent, textArea = true) {
|
||||||
// Update the textarea
|
// Update the textarea
|
||||||
if ( textArea ) document.getElementById(`pad-content`).value = newContent;
|
if ( textArea ) {
|
||||||
|
document.getElementById(`pad-content`).value = newContent;
|
||||||
|
}
|
||||||
|
|
||||||
// Update the preview
|
// Update the preview
|
||||||
document.getElementById(`textarea-preview`).innerHTML = newContent;
|
const prev = document.getElementById(`textarea-preview`);
|
||||||
// TODO: Re-run the syntax highlight
|
const shouldScroll = prev.scrollTop >= (prev.scrollHeight - Number(getComputedStyle(prev).height.replace(/px/g, ''))) * 0.98;
|
||||||
|
|
||||||
|
prev.innerHTML = escapeHtml(newContent);
|
||||||
|
|
||||||
|
prev.classList.remove(`language-undefined`);
|
||||||
|
|
||||||
|
prev.classList.forEach( c => {
|
||||||
|
if ( c.indexOf(`language-`) != -1 ) {
|
||||||
|
prev.classList.remove(c);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
try { // highlights
|
||||||
|
hljs.highlightElement(document.getElementById(`textarea-preview`));
|
||||||
|
} catch ( err ) {
|
||||||
|
console.err(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if we should follow the bottom scrolling
|
||||||
|
if (shouldScroll) {
|
||||||
|
prev.scrollTop = prev.scrollHeight;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,3 +246,16 @@ function connectSocket() {
|
|||||||
window.addEventListener(`load`, e => {
|
window.addEventListener(`load`, e => {
|
||||||
connectSocket()
|
connectSocket()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// lol
|
||||||
|
function escapeHtml(html){
|
||||||
|
const text = document.createTextNode(html);
|
||||||
|
const p = document.createElement('p');
|
||||||
|
|
||||||
|
p.appendChild(text);
|
||||||
|
const content = p.innerHTML;
|
||||||
|
p.remove();
|
||||||
|
|
||||||
|
return content;
|
||||||
|
}
|
||||||
@@ -35,7 +35,9 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2 class="mb-4">{{.title}}</h2>
|
<h2 class="mb-4" id="padTitle">
|
||||||
|
{{.title}}
|
||||||
|
</h2>
|
||||||
|
|
||||||
<div id="pad-content-area">
|
<div id="pad-content-area">
|
||||||
<div class="btn-sm btn" id="pad-content-toggler" onclick="toggleTextareaPreview()">
|
<div class="btn-sm btn" id="pad-content-toggler" onclick="toggleTextareaPreview()">
|
||||||
|
|||||||
Reference in New Issue
Block a user