Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: x.vweb static website capabilities (#20808)
- Loading branch information
Showing
5 changed files
with
63 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Host the vlang website | ||
|
||
Here is an example on how to use the vweb server's static capabilities, | ||
to host a static website from the `dist/` folder. Just run the server, | ||
it will be available at http://localhost:8080/ : | ||
|
||
```bash | ||
v run server.v | ||
``` |
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,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Website other page</title> | ||
</head> | ||
<body> | ||
<h1>Hello, another world!</h1> | ||
<p>Welcome to this another page of a demo website.</p> | ||
<p><a href="/">Click here</a> to go to main page.</p> | ||
</body> | ||
</html> |
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,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Website main page</title> | ||
</head> | ||
<body> | ||
<h1>Hello, world!</h1> | ||
<p>Welcome to this demo website.</p> | ||
<p><a href="another.html">Click here</a> to go to another page.</p> | ||
</body> | ||
</html> |
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,21 @@ | ||
module main | ||
|
||
import x.vweb | ||
import os | ||
|
||
pub struct Context { | ||
vweb.Context | ||
} | ||
|
||
pub struct App { | ||
vweb.StaticHandler | ||
} | ||
|
||
fn main() { | ||
// make sure that the working folder is the one, containing the executable, | ||
// so that 'dist' is a valid relative path from it later: | ||
os.chdir(os.dir(os.executable()))! | ||
mut app := &App{} | ||
app.handle_static('dist', true)! | ||
vweb.run[App, Context](mut app, 8080) | ||
} |
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