a mini social media app for small communities
1module main
2
3import db.pg
4import veb
5import auth
6import entity
7import os
8import webapp { App, Context, StringValidator }
9
10fn main() {
11 config := webapp.load_config_from(os.args[1])
12
13 println('-> connecting to db...')
14 mut db := pg.connect(pg.Config{
15 host: config.postgres.host
16 dbname: config.postgres.db
17 user: config.postgres.user
18 password: config.postgres.password
19 port: config.postgres.port
20 })!
21 println('<- connected')
22
23 defer {
24 db.close()
25 }
26
27 mut app := &App{
28 config: config
29 db: db
30 auth: auth.new(db)
31 }
32
33 // vfmt off
34 app.validators.username = StringValidator.new(config.user.username_min_len, config.user.username_max_len, config.user.username_pattern)
35 app.validators.password = StringValidator.new(config.user.username_min_len, config.user.username_max_len, config.user.username_pattern)
36 app.validators.nickname = StringValidator.new(config.user.nickname_min_len, config.user.nickname_max_len, config.user.nickname_pattern)
37 app.validators.user_bio = StringValidator.new(config.user.bio_min_len, config.user.bio_max_len, config.user.bio_pattern)
38 app.validators.pronouns = StringValidator.new(config.user.pronouns_min_len, config.user.pronouns_max_len, config.user.pronouns_pattern)
39 app.validators.post_title = StringValidator.new(config.post.title_min_len, config.post.title_max_len, config.post.title_pattern)
40 app.validators.post_body = StringValidator.new(config.post.body_min_len, config.post.body_max_len, config.post.body_pattern)
41 // vfmt on
42
43 app.mount_static_folder_at(app.config.static_path, '/static')!
44
45 println('-> initializing database...')
46 sql db {
47 create table entity.Site
48 create table entity.User
49 create table entity.Post
50 create table entity.Like
51 create table entity.LikeCache
52 create table entity.Notification
53 }!
54 println('<- done')
55
56 // make the website config, if it does not exist
57 app.get_or_create_site_config()
58
59 if config.dev_mode {
60 println('\033[1;31mNOTE: YOU ARE IN DEV MODE\033[0m')
61 }
62
63 veb.run[App, Context](mut app, app.config.http.port)
64}