mirror of
https://github.com/maputnik/editor.git
synced 2026-03-21 17:50:01 +00:00
Merge pull request #16 from pathmapper/static
Add option to serve directory under /static/ (supersedes #2)
This commit is contained in:
15
README.md
15
README.md
@@ -18,14 +18,14 @@ You can download a single binary for Linux, OSX or Windows from [the latest rele
|
|||||||
|
|
||||||
Simply start up a web server and access the Maputnik editor GUI at `localhost:8000`.
|
Simply start up a web server and access the Maputnik editor GUI at `localhost:8000`.
|
||||||
|
|
||||||
```
|
```bash
|
||||||
maputnik
|
maputnik
|
||||||
```
|
```
|
||||||
|
|
||||||
Expose a local style file to Maputnik allowing the web based editor
|
Expose a local style file to Maputnik allowing the web based editor
|
||||||
to save to the local filesystem.
|
to save to the local filesystem.
|
||||||
|
|
||||||
```
|
```bash
|
||||||
maputnik --file basic-v9.json
|
maputnik --file basic-v9.json
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -33,16 +33,23 @@ Watch the local style for changes and inform the editor via web socket.
|
|||||||
This makes it possible to edit the style with a local text editor and still
|
This makes it possible to edit the style with a local text editor and still
|
||||||
use Maputnik.
|
use Maputnik.
|
||||||
|
|
||||||
```
|
```bash
|
||||||
maputnik --watch --file basic-v9.json
|
maputnik --watch --file basic-v9.json
|
||||||
```
|
```
|
||||||
|
|
||||||
Choose a local port to listen on, instead of using the default port 8000.
|
Choose a local port to listen on, instead of using the default port 8000.
|
||||||
|
|
||||||
```
|
```bash
|
||||||
maputnik --port 8001
|
maputnik --port 8001
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Specify a path to a directory which, if it exists, will be served under http://localhost:8000/static/ .
|
||||||
|
Could be used to serve sprites and glyphs.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
maputnik --static ./localFolder
|
||||||
|
```
|
||||||
|
|
||||||
### API
|
### API
|
||||||
|
|
||||||
`maputnik` exposes the configured styles via a HTTP API.
|
`maputnik` exposes the configured styles via a HTTP API.
|
||||||
|
|||||||
12
maputnik.go
12
maputnik.go
@@ -16,7 +16,7 @@ func main() {
|
|||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Name = "maputnik"
|
app.Name = "maputnik"
|
||||||
app.Usage = "Server for integrating Maputnik locally"
|
app.Usage = "Server for integrating Maputnik locally"
|
||||||
app.Version = "Editor: 1.7.0; Desktop: 1.0.6"
|
app.Version = "Editor: 1.7.0; Desktop: 1.0.7"
|
||||||
|
|
||||||
app.Flags = []cli.Flag{
|
app.Flags = []cli.Flag{
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
@@ -32,6 +32,10 @@ func main() {
|
|||||||
Value: 8000,
|
Value: 8000,
|
||||||
Usage: "TCP port to listen on",
|
Usage: "TCP port to listen on",
|
||||||
},
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "static",
|
||||||
|
Usage: "Serve directory under /static/",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Action = func(c *cli.Context) error {
|
app.Action = func(c *cli.Context) error {
|
||||||
@@ -57,6 +61,12 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
staticDir := c.String("static")
|
||||||
|
if staticDir != "" {
|
||||||
|
h := http.StripPrefix("/static/", http.FileServer(http.Dir(staticDir)))
|
||||||
|
router.PathPrefix("/static/").Handler(h)
|
||||||
|
}
|
||||||
|
|
||||||
router.PathPrefix("/").Handler(http.StripPrefix("/", gui))
|
router.PathPrefix("/").Handler(http.StripPrefix("/", gui))
|
||||||
loggedRouter := handlers.LoggingHandler(os.Stdout, router)
|
loggedRouter := handlers.LoggingHandler(os.Stdout, router)
|
||||||
corsRouter := handlers.CORS(handlers.AllowedHeaders([]string{"Content-Type"}), handlers.AllowedMethods([]string{"GET", "PUT"}), handlers.AllowedOrigins([]string{"*"}), handlers.AllowCredentials())(loggedRouter)
|
corsRouter := handlers.CORS(handlers.AllowedHeaders([]string{"Content-Type"}), handlers.AllowedMethods([]string{"GET", "PUT"}), handlers.AllowedOrigins([]string{"*"}), handlers.AllowCredentials())(loggedRouter)
|
||||||
|
|||||||
Reference in New Issue
Block a user