Compare commits
No commits in common. "main" and "pretty_form" have entirely different histories.
main
...
pretty_for
8 changed files with 24 additions and 55 deletions
|
@ -3,7 +3,6 @@ ADMIN_TOKEN=
|
||||||
STRIPE_TOKEN=
|
STRIPE_TOKEN=
|
||||||
FORGEJO_URL=http://localhost:3000
|
FORGEJO_URL=http://localhost:3000
|
||||||
DATABASE_URL=sqlite://queenie.db
|
DATABASE_URL=sqlite://queenie.db
|
||||||
DATABASE_FILE=file://queenie.db
|
|
||||||
MONTHLY_LINK=
|
MONTHLY_LINK=
|
||||||
ANNUAL_LINK=
|
ANNUAL_LINK=
|
||||||
LISTENING_ADDR=127.0.0.1
|
LISTENING_ADDR=127.0.0.1
|
||||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,4 +1,4 @@
|
||||||
/target
|
/target
|
||||||
*.env
|
.env
|
||||||
*.db
|
*.db
|
||||||
*.db-*
|
*.db-*
|
||||||
|
|
|
@ -19,12 +19,9 @@ sqlx db create ; sqlx migrate run
|
||||||
Run the server for development:
|
Run the server for development:
|
||||||
|
|
||||||
```
|
```
|
||||||
cargo run -- -e .env
|
cargo run
|
||||||
```
|
```
|
||||||
|
|
||||||
The `-e` (or `--env`) option tells Queenie where to find its environment configuration file; the
|
|
||||||
default is `/etc/forgejo/queenie.env`.
|
|
||||||
|
|
||||||
The assets used in Queen come from forgejo,
|
The assets used in Queen come from forgejo,
|
||||||
so you can use a local Caddyfile to serve both forgejo and `queen`
|
so you can use a local Caddyfile to serve both forgejo and `queen`
|
||||||
(assuming that forgejo is running on localhost:3000):
|
(assuming that forgejo is running on localhost:3000):
|
||||||
|
@ -46,7 +43,3 @@ Run caddy with:
|
||||||
```
|
```
|
||||||
caddy run --config Caddyfile
|
caddy run --config Caddyfile
|
||||||
```
|
```
|
||||||
|
|
||||||
## Use in production
|
|
||||||
|
|
||||||
There's a sample systemd unit file, `queenie.service`.
|
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
[Unit]
|
|
||||||
Description=Queenie guards the kitten den.
|
|
||||||
After=syslog.target
|
|
||||||
After=network.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=simple
|
|
||||||
User=git
|
|
||||||
Group=git
|
|
||||||
WorkingDirectory=/var/lib/forgejo/
|
|
||||||
ExecStart=/var/lib/forgejo/bin/queenie --env /etc/forgejo/queenie.env
|
|
||||||
Restart=always
|
|
||||||
Environment=USER=git HOME=/home/git
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
|
@ -33,11 +33,8 @@ lazy_static! {
|
||||||
|
|
||||||
/// Displays the signup page with links to Stripe
|
/// Displays the signup page with links to Stripe
|
||||||
pub async fn get_signup() -> impl IntoResponse {
|
pub async fn get_signup() -> impl IntoResponse {
|
||||||
let annual_link = &*ANNUAL_LINK;
|
|
||||||
let monthly_link = &*MONTHLY_LINK;
|
|
||||||
SignupPage {
|
SignupPage {
|
||||||
monthly_link: Some(monthly_link.to_string()),
|
monthly_link: Some((*MONTHLY_LINK).to_string()),
|
||||||
annual_link: Some(annual_link.to_string()),
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
35
src/main.rs
35
src/main.rs
|
@ -12,6 +12,7 @@ use axum::{
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use sqlx::sqlite::{SqliteConnectOptions, SqlitePool, SqlitePoolOptions};
|
use sqlx::sqlite::{SqliteConnectOptions, SqlitePool, SqlitePoolOptions};
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
|
use tower_http::services::ServeDir;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate justerror;
|
extern crate justerror;
|
||||||
|
@ -28,10 +29,18 @@ async fn main() {
|
||||||
use handlers::handlers::{get_signup, payment_success, post_signup};
|
use handlers::handlers::{get_signup, payment_success, post_signup};
|
||||||
init();
|
init();
|
||||||
|
|
||||||
|
// for javascript and css
|
||||||
|
// TODO: figure out how to intern these contents
|
||||||
|
let assets_dir = std::env::current_dir().unwrap().join("assets");
|
||||||
|
let assets_svc = ServeDir::new(assets_dir.as_path());
|
||||||
|
|
||||||
let pool = db().await;
|
let pool = db().await;
|
||||||
|
|
||||||
|
sqlx::migrate!().run(&pool).await.unwrap();
|
||||||
|
|
||||||
// the core application, defining the routes and handlers
|
// the core application, defining the routes and handlers
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
|
.nest_service("/assets", assets_svc)
|
||||||
.stripped_clone("/signup/", get(get_signup).post(post_signup))
|
.stripped_clone("/signup/", get(get_signup).post(post_signup))
|
||||||
.stripped_clone("/payment_success/", get(payment_success))
|
.stripped_clone("/payment_success/", get(payment_success))
|
||||||
.route("/payment_success/:receipt", get(payment_success))
|
.route("/payment_success/:receipt", get(payment_success))
|
||||||
|
@ -50,14 +59,8 @@ async fn main() {
|
||||||
// li'l helpers
|
// li'l helpers
|
||||||
//-************************************************************************
|
//-************************************************************************
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[clap(version, about)]
|
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[clap(
|
#[clap(long, short)]
|
||||||
long,
|
|
||||||
short,
|
|
||||||
help = "Path to Queenie's environment config file",
|
|
||||||
default_value = "/etc/forgejo/queenie.env"
|
|
||||||
)]
|
|
||||||
pub env: OsString,
|
pub env: OsString,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,27 +76,13 @@ fn init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn db() -> SqlitePool {
|
async fn db() -> SqlitePool {
|
||||||
let dbfile = std::env::var("DATABASE_FILE").unwrap();
|
//let dbfile = std::env::var("DATABASE_URL").unwrap();
|
||||||
let opts = SqliteConnectOptions::new()
|
let opts = SqliteConnectOptions::new()
|
||||||
.foreign_keys(true)
|
.foreign_keys(true)
|
||||||
.create_if_missing(true)
|
.create_if_missing(true)
|
||||||
.journal_mode(sqlx::sqlite::SqliteJournalMode::Wal)
|
.journal_mode(sqlx::sqlite::SqliteJournalMode::Wal)
|
||||||
.filename(&dbfile)
|
|
||||||
.optimize_on_close(true, None);
|
.optimize_on_close(true, None);
|
||||||
let pool = SqlitePoolOptions::new()
|
SqlitePoolOptions::new().connect_with(opts).await.unwrap()
|
||||||
.connect_with(opts.clone())
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
sqlx::migrate!().run(&pool).await.unwrap();
|
|
||||||
|
|
||||||
let count = sqlx::query_scalar!("select count(*) from customers")
|
|
||||||
.fetch_one(&pool)
|
|
||||||
.await
|
|
||||||
.expect("could not get customer count from DB");
|
|
||||||
log::info!("Connected to DB, found {count} customers.");
|
|
||||||
|
|
||||||
pool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn mklistener() -> TcpListener {
|
async fn mklistener() -> TcpListener {
|
||||||
|
|
|
@ -34,7 +34,11 @@ impl Debug for User {
|
||||||
impl Display for User {
|
impl Display for User {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
let uname = &self.username;
|
let uname = &self.username;
|
||||||
let dname = self.displayname.as_deref().unwrap_or_default();
|
let dname = if let Some(ref n) = self.displayname {
|
||||||
|
n
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
};
|
||||||
let email = &self.email;
|
let email = &self.email;
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>{% block title %}{{ title }}{% endblock %}</title>
|
<title>{% block title %}{{ title }} - What 2 Watch{% endblock %}</title>
|
||||||
|
<link rel="stylesheet" href="/assets/ww.css">
|
||||||
<link rel="stylesheet" href="/assets/css/index.css">
|
<link rel="stylesheet" href="/assets/css/index.css">
|
||||||
<link rel="stylesheet" href="/assets/css/theme-forgejo-auto.css">
|
<link rel="stylesheet" href="/assets/css/theme-forgejo-auto.css">
|
||||||
|
|
||||||
|
@ -22,6 +23,8 @@
|
||||||
<div id="footer">
|
<div id="footer">
|
||||||
{% block footer %}{% endblock %}
|
{% block footer %}{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script src="/assets/htmx.min.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue