Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit c9504fc

Browse files
authored
Merge pull request #16 from pathmapper/static
Add option to serve directory under /static/ (supersedes #2)
2 parents c264cd1 + b7ef094 commit c9504fc

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,38 @@ You can download a single binary for Linux, OSX or Windows from [the latest rele
1818

1919
Simply start up a web server and access the Maputnik editor GUI at `localhost:8000`.
2020

21-
```
21+
```bash
2222
maputnik
2323
```
2424

2525
Expose a local style file to Maputnik allowing the web based editor
2626
to save to the local filesystem.
2727

28-
```
28+
```bash
2929
maputnik --file basic-v9.json
3030
```
3131

3232
Watch the local style for changes and inform the editor via web socket.
3333
This makes it possible to edit the style with a local text editor and still
3434
use Maputnik.
3535

36-
```
36+
```bash
3737
maputnik --watch --file basic-v9.json
3838
```
3939

4040
Choose a local port to listen on, instead of using the default port 8000.
4141

42-
```
42+
```bash
4343
maputnik --port 8001
4444
```
4545

46+
Specify a path to a directory which, if it exists, will be served under http://localhost:8000/static/ .
47+
Could be used to serve sprites and glyphs.
48+
49+
```bash
50+
maputnik --static ./localFolder
51+
```
52+
4653
### API
4754

4855
`maputnik` exposes the configured styles via a HTTP API.

maputnik.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func main() {
1616
app := cli.NewApp()
1717
app.Name = "maputnik"
1818
app.Usage = "Server for integrating Maputnik locally"
19-
app.Version = "Editor: 1.7.0; Desktop: 1.0.6"
19+
app.Version = "Editor: 1.7.0; Desktop: 1.0.7"
2020

2121
app.Flags = []cli.Flag{
2222
&cli.StringFlag{
@@ -32,6 +32,10 @@ func main() {
3232
Value: 8000,
3333
Usage: "TCP port to listen on",
3434
},
35+
&cli.StringFlag{
36+
Name: "static",
37+
Usage: "Serve directory under /static/",
38+
},
3539
}
3640

3741
app.Action = func(c *cli.Context) error {
@@ -57,6 +61,12 @@ func main() {
5761
}
5862
}
5963

64+
staticDir := c.String("static")
65+
if staticDir != "" {
66+
h := http.StripPrefix("/static/", http.FileServer(http.Dir(staticDir)))
67+
router.PathPrefix("/static/").Handler(h)
68+
}
69+
6070
router.PathPrefix("/").Handler(http.StripPrefix("/", gui))
6171
loggedRouter := handlers.LoggingHandler(os.Stdout, router)
6272
corsRouter := handlers.CORS(handlers.AllowedHeaders([]string{"Content-Type"}), handlers.AllowedMethods([]string{"GET", "PUT"}), handlers.AllowedOrigins([]string{"*"}), handlers.AllowCredentials())(loggedRouter)

0 commit comments

Comments
 (0)