gnoweb

package
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2025 License: UNKNOWN not legal advice Imports: 0 Imported by: 0

README

gnoweb

gnoweb is a universal web frontend for the gno.land blockchain.

This README provides instructions on how to set up and run gnoweb for development purposes.

Prerequisites

Before you begin, ensure you have the following software installed on your machine:

  • Node.js: Required for running JavaScript and CSS build tools.
  • Go: Required for building gnoweb

Development

To start the development environment, which runs multiple development tools in parallel, use the following command:

make dev

This will:

  • Start a Go server in development mode and watch for any Go files change (targeting localhost).
  • Enable Tailwind CSS in watch mode to automatically compile CSS changes.
  • Use esbuild in watch mode to automatically transpile and bundle TypeScript changes.

You can customize the behavior of the Go server using the DEV_REMOTE and CHAIN_ID environment variables. For example, to use portal-loop as the target, run:

CHAIN_ID=portal-loop DEV_REMOTE=https://rpc.gno.land make dev

Generate

To generate the public assets for the project, including static assets (fonts, CSS and JavaScript... files), run the following command. This should be used while editing CSS, JS, or any asset files:

make generate

Documentation

Index

Constants

View Source
const DefaultChainDomain = "gno.land"

Variables

View Source
var (
	ErrURLMalformedPath   = errors.New("malformed URL path")
	ErrURLInvalidPathKind = errors.New("invalid path kind")
)
View Source
var Aliases = map[string]string{
	"/":           "/r/gnoland/home",
	"/about":      "/r/gnoland/pages:p/about",
	"/gnolang":    "/r/gnoland/pages:p/gnolang",
	"/ecosystem":  "/r/gnoland/pages:p/ecosystem",
	"/partners":   "/r/gnoland/pages:p/partners",
	"/testnets":   "/r/gnoland/pages:p/testnets",
	"/start":      "/r/gnoland/pages:p/start",
	"/license":    "/r/gnoland/pages:p/license",
	"/contribute": "/r/gnoland/pages:p/contribute",
	"/events":     "/r/gnoland/events",
}

Aliases are gnoweb paths that are rewritten using AliasAndRedirectMiddleware.

View Source
var Redirects = map[string]string{
	"/r/demo/boards:gnolang/6": "/r/demo/boards:gnolang/3",
	"/blog":                    "/r/gnoland/blog",
	"/gor":                     "/contribute",
	"/game-of-realms":          "/contribute",
	"/grants":                  "/partners",
	"/language":                "/gnolang",
	"/getting-started":         "/start",
}

Redirect are gnoweb paths that are redirected using AliasAndRedirectMiddleware.

Functions

func AliasAndRedirectMiddleware

func AliasAndRedirectMiddleware(next http.Handler, analytics bool) http.Handler

AliasAndRedirectMiddleware redirects all incoming requests whose path matches any of the Redirects to the corresponding URL; and rewrites the URL path for incoming requests which match any of the Aliases.

func AssetHandler

func AssetHandler() http.Handler

AssetHandler returns the handler to serve static assets. If cache is true, these will be served using the static files embedded in the binary; otherwise they will served from the filesystem.

func DevAssetHandler

func DevAssetHandler(path, dir string) http.Handler

func NewRouter

func NewRouter(logger *slog.Logger, cfg *AppConfig) (http.Handler, error)

NewRouter initializes the gnoweb router, with the given logger and config.

Types

type AppConfig

type AppConfig struct {
	// UnsafeHTML, if enabled, allows to use HTML in the markdown.
	UnsafeHTML bool
	// Analytics enables SimpleAnalytics.
	Analytics bool
	// NodeRemote is the remote address of the gno.land node.
	NodeRemote string
	// RemoteHelp is the remote of the gno.land node, as used in the help page.
	RemoteHelp string
	// ChainID is the chain id, used for constructing the help page.
	ChainID string
	// AssetsPath is the base path to the gnoweb assets.
	AssetsPath string
	// AssetDir, if set, will be used for assets instead of the embedded public directory
	AssetsDir string
	// FaucetURL, if specified, will be the URL to which `/faucet` redirects.
	FaucetURL string
}

AppConfig contains configuration for the gnoweb.

func NewDefaultAppConfig

func NewDefaultAppConfig() *AppConfig

NewDefaultAppConfig returns a new default AppConfig. The default sets 127.0.0.1:26657 as the remote node, "dev" as the chain ID and sets up Assets to be served on /public/.

type Formatter

type Formatter interface {
	Format(w io.Writer, iterator chroma.Iterator) error
}

type GnoURL

type GnoURL struct {
	Domain   string     // gno.land
	Path     string     // /r/demo/users
	Args     string     // jae
	WebQuery url.Values // help&a=b
	Query    url.Values // c=d
}

GnoURL decomposes the parts of an URL to query a realm.

func ParseGnoURL

func ParseGnoURL(u *url.URL) (*GnoURL, error)

func (GnoURL) EncodeArgs

func (url GnoURL) EncodeArgs() string

func (GnoURL) EncodePath

func (url GnoURL) EncodePath() string

func (GnoURL) EncodeWebPath

func (url GnoURL) EncodeWebPath() string

func (GnoURL) Kind

func (url GnoURL) Kind() PathKind

type Metadata

type Metadata struct {
	*md.Toc
}

type PathKind

type PathKind byte
const (
	KindInvalid PathKind = 0
	KindRealm   PathKind = 'r'
	KindPure    PathKind = 'p'
)

type StaticMetadata

type StaticMetadata struct {
	AssetsPath string
	ChromaPath string
	RemoteHelp string
	ChainId    string
	Analytics  bool
}

type WebClient

type WebClient struct {
	// contains filtered or unexported fields
}

func NewWebClient

func NewWebClient(log *slog.Logger, cl *client.RPCClient, m goldmark.Markdown) *WebClient

func (*WebClient) Functions

func (s *WebClient) Functions(pkgPath string) ([]vm.FunctionSignature, error)

func (*WebClient) Render

func (s *WebClient) Render(w io.Writer, pkgPath string, args string) (*Metadata, error)

func (*WebClient) SourceFile

func (s *WebClient) SourceFile(path, fileName string) ([]byte, error)

func (*WebClient) Sources

func (s *WebClient) Sources(path string) ([]string, error)

type WebHandler

type WebHandler struct {
	// contains filtered or unexported fields
}

func NewWebHandler

func NewWebHandler(logger *slog.Logger, cfg WebHandlerConfig) *WebHandler

func (*WebHandler) Get

func (h *WebHandler) Get(w http.ResponseWriter, r *http.Request)

func (*WebHandler) ServeHTTP

func (h *WebHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type WebHandlerConfig

type WebHandlerConfig struct {
	Meta         StaticMetadata
	RenderClient *WebClient
	Formatter    Formatter
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL