func Initialize(ds *store.InMemory, c Config) *Server {
	s := Server{
		Router: httprouter.New(),
		Config: c,
	}
	if s.Config.CORSEnabled {
		log.Println(DEBUG, "server:", fmt.Sprintf("Setting CORS origin to %s", c.CORSOrigins))
	}
	s.Router.NotFound = http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
		resp.Header().Set("Content-Type", "text/plain; charset=UTF-8")
		resp.WriteHeader(http.StatusNotFound)
		fmt.Fprintf(resp, "Not Found")
	})
	s.Router.HandleMethodNotAllowed = true
	s.Router.MethodNotAllowed = http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
		resp.Header().Set("Content-Type", "text/plain; charset=UTF-8")
		resp.WriteHeader(http.StatusMethodNotAllowed)
		fmt.Fprintf(resp, "Method Not Allowed")
	})
	s.Router.GET("/", defaultRedirectRoute)
	s.Router.GET("/api", defaultRedirectRoute)
	s.Router.GET("/api/", defaultRoute)
	sock, err := socket.Create(ds)
	sock.ID = c.ID
	if err != nil {
		log.Fatal(err)
	}
	go sock.Listen()
	s.Router.HandlerFunc("GET", "/socket.io/", func(w http.ResponseWriter, r *http.Request) {
		if s.Config.CORSEnabled {
			regx := regexp.MustCompile(`https?:\/\/`)
			pro := r.Header.Get("Origin")
			ro := regx.ReplaceAllString(pro, "")
			if len(ro) > 0 {
				log.Println(DEBUG, "server:", fmt.Sprintf("Comparing incoming request host %s, with CORS Origins (%s)", ro, s.Config.CORSOrigins))
				po := strings.Split(s.Config.CORSOrigins, ",")
				for i := 0; i < len(po); i++ {
					o := regx.ReplaceAllString(po[i], "")
					if strings.Contains(strings.Trim(ro, " "), strings.Trim(o, " ")) {
						log.Println(DEBUG, "server:", fmt.Sprintf("Sending CORS Access-Control-Allow-Origin for %s", po[i]))
						w.Header().Set("Access-Control-Allow-Origin", pro)
						break
					}
				}
			}
			w.Header().Set("Access-Control-Allow-Credentials", "true")
		}
		sock.ServeHTTP(w, r)
	})
	operator.Routes(s.Router, ds)
	client.Routes(s.Router, ds)
	chat.Routes(s.Router, ds)
	webhook.Routes(s.Router, ds)
	return &s
}
/*
Initialize takes a Store and ServerConfig starts listening on port and host
provided by a ServerConfig
package rest
import (
	"fmt"
	"log"
	"net/http"
	"regexp"
	"strings"
	"github.com/julienschmidt/httprouter"  
	"github.com/minimalchat/daemon/pkg/api/chat"
	"github.com/minimalchat/daemon/pkg/api/client"
	"github.com/minimalchat/daemon/pkg/api/operator"
	"github.com/minimalchat/daemon/pkg/api/webhook"
	"github.com/minimalchat/daemon/pkg/server/socket"
	"github.com/minimalchat/daemon/pkg/store"  
)
const (
	DEBUG   string = "DEBUG"
	INFO    string = "INFO"
	WARNING string = "WARN"
	ERROR   string = "ERROR"
	FATAL   string = "FATAL"
)
type Server struct {
	Router *httprouter.Router
	Config
}
type Config struct {
	Protocol string
	Port     string
	Host     string
	ID string
	SSLCertFile string
	SSLKeyFile  string
	SSLPort     int
	CORSOrigins string
	CORSEnabled bool
}