-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
205 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cmd | ||
|
||
import ( | ||
"crypto/rand" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/mattn/go-isatty" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func generateToken(n int) (string, error) { | ||
const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | ||
bytes := make([]byte, n) | ||
if _, err := rand.Read(bytes); err != nil { | ||
return "", err | ||
} | ||
|
||
for i := 0; i < n; i++ { | ||
bytes[i] = letters[bytes[i]%byte(len(letters))] | ||
} | ||
|
||
return string(bytes), nil | ||
} | ||
|
||
func NewCmdToken() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "token", | ||
Short: "Generate a random token", | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
token, err := generateToken(16) | ||
if err != nil { | ||
return fmt.Errorf("failed to generate token: %w", err) | ||
} | ||
|
||
if isatty.IsTerminal(os.Stdout.Fd()) { | ||
fmt.Println(token) | ||
} else { | ||
fmt.Print(token) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Private Apps | ||
|
||
You can automatically protects private apps behind a login prompt. In order to achieve this, you'll need to: | ||
|
||
1. Use the `smallweb token` command to generate a new token. | ||
|
||
```console | ||
$ smallweb token | ||
SF7RZt9shD6UnUcl | ||
``` | ||
|
||
1. Add an `tokens` property to your global config. | ||
|
||
```json | ||
// ~/.config/smallweb/config.json | ||
{ | ||
"tokens": ["SF7RZt9shD6UnUcl"] | ||
} | ||
``` | ||
|
||
1. Set the private field to true in your app's config. | ||
|
||
```json | ||
// ~/smallweb/private-app/smallweb.json | ||
{ | ||
"private": true | ||
} | ||
``` | ||
|
||
The next time you'll try to access the app, you'll be prompted with a basic auth dialog. | ||
|
||
Use the token as the username, and leave the password empty. | ||
|
||
Your tokens are also used to protect internal services that smallweb provides, such as: | ||
|
||
- `webdav.<domain>`: A webdav server allowing you to access your files. | ||
- `cli.<domain>`: A web interface to run cli commands. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# App Sandbox | ||
|
||
Smallweb apps have access to: | ||
|
||
- read and write access to their own directory, and the deno cache directory. | ||
- access to the network, to make HTTP requests. | ||
- access to the env files defined in the global config and in the `.env` file in the app directory. | ||
|
||
This sandbox protects the host system from malicious code, and ensures that apps can only access the resources they need. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
# Templates | ||
|
||
Smallweb comes with a list of templates to help you get started with your project. You can use the `smallweb init` command to create a new project from a template. | ||
Smallweb comes with a list of templates to help you get started with your project. You can use the `smallweb init` command to create a new project. | ||
|
||
```sh | ||
# create a new project in the current directory | ||
smallweb init | ||
# create a new project in a specific directory | ||
smallweb init <directory> | ||
``` | ||
|
||
You can also specify custom a template to use: | ||
|
||
```sh | ||
smallweb init --template pomdtr/smallweb-template-http | ||
``` | ||
|
||
Any github repository can be used as a template. View a list of the available templates [here](https://github.com/topic/smallweb-template). | ||
|
||
To create your own template, just add the `smallweb-template` topic to your repository. | ||
To create your own template, just add the `smallweb-template` topic to your repository, and it will be automatically added to the list of available templates. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters