Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Favicon #107

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
13 changes: 13 additions & 0 deletions cmd/kjudge/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (

var (
dbfile = flag.String("file", "kjudge.db", "Path to the database file.")
faviconfile = flag.String("favicon", "", "Path to favicon file. Will not be served if not specified.")

sandboxImpl = flag.String("sandbox", "isolate", "The sandbox implementation to be used (isolate, raw). Defaults to isolate.")
port = flag.Int("port", 8088, "The port for the server to listen on.")
verbose = flag.Bool("verbose", false, "Log every http requests")
Expand All @@ -42,6 +44,17 @@ func main() {
opts = append(opts, server.Verbose())
}

if *faviconfile != "" {
log.Printf("Serving favicon from %s", *faviconfile)
opt, err := server.Favicon(*faviconfile)
if err != nil {
panic(err)
}
opts = append(opts, opt)
} else {
log.Printf("Not serving favicon")
}

// Start the queue
queue := worker.Queue{Sandbox: sandbox, DB: db}

Expand Down
19 changes: 16 additions & 3 deletions scripts/start_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ showUsage() {
- CERT_O [nki inc.] Certificate Organization Name
- CERT_CN [kjudge] Certificate Common name
- CERT_EMAIL [[email protected]] Certificate Email address
- CERT_ALTNAMES [IP:127.0.0.1,DNS:localhost] A list of hosts that kjudge will be listening on, either by IP (as 'IP:1.2.3.4') or DNS (as 'DNS:google.com'), separated by ','"
- CERT_ALTNAMES [IP:127.0.0.1,DNS:localhost] A list of hosts that kjudge will be listening on, either by IP (as 'IP:1.2.3.4') or DNS (as 'DNS:google.com'), separated by ','

favicon usage:
If /data/favicon.ico, start kjudge with favicon support."
}

if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
Expand All @@ -43,8 +46,18 @@ case ${HTTPS} in
;;
esac

cmd="kjudge"
args="-file /data/kjudge.db"

if [ "${useHTTPS}" = true ]; then
kjudge -port 443 -file /data/kjudge.db -https /certs "$@"
args="$args -port 443 -https /certs"
else
kjudge -port 80 -file /data/kjudge.db "$@"
args="$args -port 80"
fi

if [ -f "/data/favicon.ico" ]; then
args="$args -favicon /data/favicon.ico"
fi

# shellcheck disable=SC2086
$cmd $args "$@"
16 changes: 16 additions & 0 deletions server/opts.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package server

import (
"os"

"github.com/pkg/errors"
)

// Opt represents an option for the server.
type Opt func(s *Server)

Expand All @@ -9,3 +15,13 @@ func Verbose() Opt {
s.verbose = true
}
}

// Favicon makes the server serves given file at /favicon.ico
func Favicon(path string) (Opt, error) {
if _, err := os.Stat(path); err != nil {
return nil, errors.Wrap(err, "while searching for favicon")
}
return func(s *Server) {
s.faviconPath = path
}, nil
}
10 changes: 9 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ type Server struct {
db *db.DB
echo *echo.Echo

verbose bool
verbose bool
faviconPath string
}

// New creates a new server.
func New(db *db.DB, opts ...Opt) (*Server, error) {
s := &Server{
db: db,
echo: echo.New(),

verbose: false,
faviconPath: "",
natsukagami marked this conversation as resolved.
Show resolved Hide resolved
}

for _, opt := range opts {
Expand Down Expand Up @@ -70,6 +74,10 @@ func New(db *db.DB, opts ...Opt) (*Server, error) {

s.SetupProfiling()

if s.faviconPath != "" {
s.echo.File("/favicon.ico", s.faviconPath)
}

au, err := auth.NewAdmin()
if err != nil {
return nil, err
Expand Down
Loading