package web

import (
	"fmt"
	"github.com/gorilla/csrf"
	"log"
	"net/http"
	"status/config"
	"status/storage"
	"status/vpub"
	"status/web/handler"
	"status/web/session"
)

func Serve(data *storage.Storage, v vpub.Vpub, cfg *config.Config) error {
	var err error
	sess := session.New(cfg.SessionKey, data)
	s, err := handler.New(cfg, sess, data, v)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Starting HTTP server on port 8000\n")
	err = http.ListenAndServe(":8000", csrf.Protect([]byte("32-byte-long-auth-key"), csrf.MaxAge(0))(s))
	return err
}
