File: main.go

package info (click to toggle)
golang-github-gorilla-csrf 1.7.2%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 332 kB
  • sloc: javascript: 38; makefile: 30
file content (42 lines) | stat: -rw-r--r-- 859 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// +build ignore

package main

import (
	"fmt"
	"log"
	"net/http"
	"os"
	"time"

	"github.com/gorilla/handlers"
	"github.com/gorilla/mux"
)

func main() {
	router := mux.NewRouter()

	loggingMiddleware := func(h http.Handler) http.Handler {
		return handlers.LoggingHandler(os.Stdout, h)
	}
	router.Use(loggingMiddleware)

	wd, err := os.Getwd()
	if err != nil {
		log.Panic(err)
	}
	// change this directory to point at a different Javascript frontend to serve
	httpStaticAssetsDir := http.Dir(fmt.Sprintf("%s/../frontends/axios/", wd))

	router.PathPrefix("/").Handler(http.FileServer(httpStaticAssetsDir))

	server := &http.Server{
		Handler:      router,
		Addr:         "localhost:8081",
		ReadTimeout:  60 * time.Second,
		WriteTimeout: 60 * time.Second,
	}

	fmt.Println("starting http server on localhost:8081")
	log.Panic(server.ListenAndServe())
}