upd
This commit is contained in:
parent
ba1f5f4951
commit
b67b854b88
@ -57,3 +57,9 @@ make
|
|||||||
docker build -t habraview:latest .
|
docker build -t habraview:latest .
|
||||||
docker run --rm -p 8888:8888 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'
|
40
habraview.v
40
habraview.v
@ -12,13 +12,7 @@ pub struct Context {
|
|||||||
veb.Context
|
veb.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {}
|
||||||
veb.StaticHandler
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Response {
|
|
||||||
msg string
|
|
||||||
}
|
|
||||||
|
|
||||||
const embedded = {
|
const embedded = {
|
||||||
'style.css': $embed_file('assets/style.css')
|
'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 {
|
fn (a &App) index(mut ctx Context) veb.Result {
|
||||||
article_id := ctx.query['id'] or { habr.get_id_from_url(ctx.query['url']) or { '' } }
|
article_id := ctx.query['id'] or { habr.get_id_from_url(ctx.query['url']) or { '' } }
|
||||||
client := habr.Habr.new()
|
client := habr.Habr.new()
|
||||||
raw_article := client.get_article(article_id.int()) or {
|
raw_article := client.get_article(article_id.int()) or { return ctx.server_error(err.str()) }
|
||||||
return ctx.json(Response{ msg: err.str() })
|
|
||||||
}
|
|
||||||
raw_comments := client.get_article_comments(article_id.int()) or {
|
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)
|
article := habr.Article.parse(raw_article)
|
||||||
comments := habr.Comments.parse(raw_comments)
|
comments := habr.Comments.parse(raw_comments)
|
||||||
return $veb.html()
|
return $veb.html()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn runserver(host string, port int) ! {
|
fn serve(host string, port int) ! {
|
||||||
mut app := &App{}
|
mut app := &App{}
|
||||||
mut ipversion := net.AddrFamily.ip
|
mut ipversion := net.AddrFamily.ip
|
||||||
if host.contains(':') {
|
if host.contains(':') {
|
||||||
@ -65,16 +57,7 @@ fn runserver(host string, port int) ! {
|
|||||||
veb.run_at[App, Context](mut app, params)!
|
veb.run_at[App, Context](mut app, params)!
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn run_server(cmd cli.Command) ! {
|
||||||
mut app := cli.Command{
|
|
||||||
name: 'habraview'
|
|
||||||
usage: '[host][:port]'
|
|
||||||
description: 'Habr.com posts viewer.'
|
|
||||||
version: $d('habraview_version', '0.0.0')
|
|
||||||
defaults: struct {
|
|
||||||
man: false
|
|
||||||
}
|
|
||||||
execute: fn (cmd cli.Command) ! {
|
|
||||||
mut host, mut port := '0.0.0.0', '8888'
|
mut host, mut port := '0.0.0.0', '8888'
|
||||||
if cmd.args.len == 1 {
|
if cmd.args.len == 1 {
|
||||||
host, port = urllib.split_host_port(cmd.args[0])
|
host, port = urllib.split_host_port(cmd.args[0])
|
||||||
@ -85,8 +68,19 @@ fn main() {
|
|||||||
port = '8888'
|
port = '8888'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
runserver(host, port.int())!
|
serve(host, port.int())!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
mut app := cli.Command{
|
||||||
|
name: 'habraview'
|
||||||
|
usage: '[host][:port]'
|
||||||
|
description: 'Habr.com posts viewer.'
|
||||||
|
version: $d('habraview_version', '0.0.0')
|
||||||
|
defaults: struct {
|
||||||
|
man: false
|
||||||
|
}
|
||||||
|
execute: run_server
|
||||||
}
|
}
|
||||||
app.setup()
|
app.setup()
|
||||||
app.parse(os.args)
|
app.parse(os.args)
|
||||||
|
Loading…
Reference in New Issue
Block a user