Giter Site home page Giter Site logo

masterevarior / cocopasty Goto Github PK

View Code? Open in Web Editor NEW
35.0 35.0 0.0 3.67 MB

✍️A small copy-and-paste app for selfhosting

License: MIT License

JavaScript 7.55% HTML 6.75% Vue 37.13% Dockerfile 7.70% Go 38.30% Shell 2.56%
docker docker-compose golang mit-license redis selfhosted vuejs vuejs3

cocopasty's Introduction

Hallihallo 👋

Let me tell you a little bit about myself

Things I like to play around with

Languages Frameworks & Libraries Tools
Java JavaScript Golang Vue Spring Boot Project Lombok IntelliJ Docker Visual Studio Code Cloud Foundry Jenkins Ansible

Some statistics about my account

Top Langs My github stats

cocopasty's People

Contributors

dependabot[bot] avatar imgbotapp avatar masterevarior avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

cocopasty's Issues

[Feature] Autofocus and key commands

I want Cocopasty to have the following features so that it is more convenient:

  • Automatically focus on the input text area once the webpage is loaded.
  • Press Ctrl + C to copy whole text even when no text is selected or the text area is not focused.
  • Press Ctrl + Enter to save text.

Code Improvements

Did a code review of your backend, found some things that should be improved.

In General

  • All your methods are currently private. Change the util and database function to public (by capitalization of the 1. letter).
  • Most of your logs are useless. They describe the working operations which don't benefit the debugging process. In readEntry() for example you log Getting value from Redis... and if it fails you log the error. Why not log Failed to get value from Redis: <error>. That way you know where it failed.
  • Also for error handling you might want to look into an error library.
    Shameless self promotion: I'm currently writing a framework with it's own errorlibrary, where the errors print the stacktrace. The idea behind it is to just return the errors until they are handled or just logged, where you know the source of it.

main.go

  • line 14: json tag incorrectly set, should be json:"Code"
  • line 38 & 66: Implement middleware to log all requests
  • line 40: Checking the Content-Type in every request manually is a bad approach. Better to write a middleware that checks if the Content-Type header is accurate and then expect the content it the correct format in the handlerfunc.
  • line 49: Since json.NewDecoder doesn't return an error you could combine it with the next line: err := json.NewDecoder(r.Body).Decode(&newSnippet)
  • line 53: Why are you logging that it couldn't parse the json, and then print (not even println) the error? It would be better to send the error back fmt.Fprintf(err.Error)
  • line 61 & 79: like 38 & 66 write a middleware for it
  • line 62: this line is unnecessary, default is 200

database.go
line 11: You can combine your var declarations like this:

var (
	connection *redis.Client
	ctx        context.Context
)
  • line 12: don't use global context, instead get it from the requests r.Context() and pass it on
  • line 30: don't check if connection is nil on every call. Instead create a function called init which will be executed at startup and set the connection then.
  • line 35: connection.Set does NOT return an error and the handling and logging is incorrect. I'm unfamiliar with the redis library you're using, but from the looks of it you get the error by calling the Err method.
  • line 43: if a function can fail, then it should return an error and not just a bool. This way the error is passed on and can be properly handled.

util.go

  • line 14: in general you check if you have an error and then handle it, or return early. So it's better to replace line 15 with return and put log.SetLevel(parsedLevel) after the if. If you still want to print out the current loglevel you should put the log at the start with defer (defer executes the code after it when the functions is exited, so after return).

go.mod

  • line 1: set the module properly github.com/MasterEvariour/cocopasty/cocopasty-backend. I'm unsure of how well this works, as go uses git tags for versioning of the project. I recommend having the front and backend in separate repositories.

Code not saved

Describe the bug
When clicking save, and refreshing the page, the code is not saved and the text box is empty

To Reproduce
docker-compose deploy install, in swarm mode.
navigate to page, type code, click save, refresh page

Expected behavior
Clicking save would save the code, refreshing the page would show the code saved

Desktop (please complete the following information):

  • mac os or windows with FF

Additional context
tested both with Keycloak and traefik in front of cocopasty, and without (port redirection).
No errors in the logs whatsoever.

Behind reverse proxy https, mixed content Warning

Hello!

Trying to run this behind a reverse proxy to serve with https but im getting the same issues as described here: #5 . Nothing gets saved.

When checking the browser console for errors i can see edge/chrome throwing mixed content warnings and not allowing the connection to the backend since its http.

If i add the proxy conf with: add_header 'Content-Security-Policy' 'upgrade-insecure-requests'; so all http calls are upgraded to https i instead get SSL errors in the console which results in also nothing getting saved.

Anything that can be done regarding to this, thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.