upd
This commit is contained in:
parent
ba1f5f4951
commit
b67b854b88
@ -56,4 +56,10 @@ make
|
||||
```
|
||||
docker build -t habraview:latest .
|
||||
docker run --rm -p 8888:8888 habraview:latest
|
||||
```
|
||||
```
|
||||
|
||||
или:
|
||||
|
||||
```
|
||||
docker compose up -d
|
||||
```
|
||||
|
8
docker-compose.yaml
Normal file
8
docker-compose.yaml
Normal file
@ -0,0 +1,8 @@
|
||||
services:
|
||||
habraview:
|
||||
image: habraview:latest
|
||||
build: .
|
||||
container_name: habraview
|
||||
restart: always
|
||||
ports:
|
||||
- '8888:8888'
|
44
habraview.v
44
habraview.v
@ -12,13 +12,7 @@ pub struct Context {
|
||||
veb.Context
|
||||
}
|
||||
|
||||
pub struct App {
|
||||
veb.StaticHandler
|
||||
}
|
||||
|
||||
struct Response {
|
||||
msg string
|
||||
}
|
||||
pub struct App {}
|
||||
|
||||
const embedded = {
|
||||
'style.css': $embed_file('assets/style.css')
|
||||
@ -40,18 +34,16 @@ fn (a &App) assets(mut ctx Context, filename string) veb.Result {
|
||||
fn (a &App) index(mut ctx Context) veb.Result {
|
||||
article_id := ctx.query['id'] or { habr.get_id_from_url(ctx.query['url']) or { '' } }
|
||||
client := habr.Habr.new()
|
||||
raw_article := client.get_article(article_id.int()) or {
|
||||
return ctx.json(Response{ msg: err.str() })
|
||||
}
|
||||
raw_article := client.get_article(article_id.int()) or { return ctx.server_error(err.str()) }
|
||||
raw_comments := client.get_article_comments(article_id.int()) or {
|
||||
return ctx.json(Response{ msg: err.str() })
|
||||
return ctx.server_error(err.str())
|
||||
}
|
||||
article := habr.Article.parse(raw_article)
|
||||
comments := habr.Comments.parse(raw_comments)
|
||||
return $veb.html()
|
||||
}
|
||||
|
||||
fn runserver(host string, port int) ! {
|
||||
fn serve(host string, port int) ! {
|
||||
mut app := &App{}
|
||||
mut ipversion := net.AddrFamily.ip
|
||||
if host.contains(':') {
|
||||
@ -65,6 +57,20 @@ fn runserver(host string, port int) ! {
|
||||
veb.run_at[App, Context](mut app, params)!
|
||||
}
|
||||
|
||||
fn run_server(cmd cli.Command) ! {
|
||||
mut host, mut port := '0.0.0.0', '8888'
|
||||
if cmd.args.len == 1 {
|
||||
host, port = urllib.split_host_port(cmd.args[0])
|
||||
if host.is_blank() {
|
||||
host = '0.0.0.0'
|
||||
}
|
||||
if port.is_blank() {
|
||||
port = '8888'
|
||||
}
|
||||
}
|
||||
serve(host, port.int())!
|
||||
}
|
||||
|
||||
fn main() {
|
||||
mut app := cli.Command{
|
||||
name: 'habraview'
|
||||
@ -74,19 +80,7 @@ fn main() {
|
||||
defaults: struct {
|
||||
man: false
|
||||
}
|
||||
execute: fn (cmd cli.Command) ! {
|
||||
mut host, mut port := '0.0.0.0', '8888'
|
||||
if cmd.args.len == 1 {
|
||||
host, port = urllib.split_host_port(cmd.args[0])
|
||||
if host.is_blank() {
|
||||
host = '0.0.0.0'
|
||||
}
|
||||
if port.is_blank() {
|
||||
port = '8888'
|
||||
}
|
||||
}
|
||||
runserver(host, port.int())!
|
||||
}
|
||||
execute: run_server
|
||||
}
|
||||
app.setup()
|
||||
app.parse(os.args)
|
||||
|
Loading…
Reference in New Issue
Block a user