Files
coder/coderd/coderd.go
Bryan 4dc6e35c24 feat: Bundle UI into coderd; add ./develop.sh script (#28)
This change bundles the static assets like we have for v1 - using the [`embed`](https://pkg.go.dev/embed) go package. Fixes #22 

In addition, it sets up a development script that runs `coderd` locally and serves the front-end, with hot-reloading. The script used is `./develop.sh`:

![2022-01-14 17 30 14](https://user-images.githubusercontent.com/88213859/149603926-f673d3d3-ba12-4eda-bcdd-427252405480.gif)

> NOTE: The UI is still placeholder, of course. Need to start testing out a simple, placeholder flow for the new v2 world as a next step

Summary of changes:
- Add build steps for `go` in the `Makefile`
  - Add a step for production build, in which we use the `embed` tag
  - Add a step for development, which doesn't need the `embed` tag - so we don't need to build the front-end twice
- Add `next export` build step to output front-end artifacts in `out`
- Add a `site` package for `go`
  - Add `embed_static.go` and `embed.go`. This is mostly brought in as-is from v1, except removing some intercom/sentry CSP entries that we aren't using.
- Add a [next development server](https://nextjs.org/docs/advanced-features/custom-server)
- Add a `v2-dev` script, that runs `coderd` and the `next` dev server side-by-side
- Use the `site` package as the fallback handler.
- Add `.gitignore` entries for additional build collateral
2022-01-18 13:13:19 -08:00

34 lines
680 B
Go

package coderd
import (
"net/http"
"cdr.dev/slog"
"github.com/coder/coder/database"
"github.com/coder/coder/site"
"github.com/go-chi/chi"
"github.com/go-chi/render"
)
// Options are requires parameters for Coder to start.
type Options struct {
Logger slog.Logger
Database database.Store
}
// New constructs the Coder API into an HTTP handler.
func New(options *Options) http.Handler {
r := chi.NewRouter()
r.Route("/api/v2", func(r chi.Router) {
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
render.JSON(w, r, struct {
Message string `json:"message"`
}{
Message: "👋",
})
})
})
r.NotFound(site.Handler().ServeHTTP)
return r
}