changed /submit route to relative, and fixed output_file path definition
This commit is contained in:
Generated
+1
-1
@@ -351,7 +351,7 @@ checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
|
||||
|
||||
[[package]]
|
||||
name = "form-generator"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"askama",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "form-generator"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
{
|
||||
packages.default = pkgs.rustPlatform.buildRustPackage {
|
||||
pname = "form-generator";
|
||||
version = "0.1.0";
|
||||
version = "0.1.1";
|
||||
|
||||
src = ./.;
|
||||
cargoLock = {
|
||||
|
||||
+4
-3
@@ -45,7 +45,6 @@ struct FieldDef {
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct AppConfig {
|
||||
json_output: String,
|
||||
submit_button: String,
|
||||
fields: Vec<FieldDef>,
|
||||
}
|
||||
@@ -60,6 +59,7 @@ struct ResponseEntry {
|
||||
struct AppState {
|
||||
cfg: Arc<AppConfig>,
|
||||
file_lock: Arc<Mutex<()>>,
|
||||
output_file: String,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
@@ -74,7 +74,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
tracing::info!(
|
||||
"Loaded config: '{}', writing answers to '{}' with {} fields",
|
||||
cli.config_path,
|
||||
cfg.json_output,
|
||||
cli.output_file,
|
||||
cfg.fields.len()
|
||||
);
|
||||
|
||||
@@ -105,6 +105,7 @@ async fn main() -> anyhow::Result<()> {
|
||||
let state = AppState {
|
||||
cfg: Arc::new(cfg),
|
||||
file_lock: Arc::new(Mutex::new(())),
|
||||
output_file: cli.output_file.clone(),
|
||||
};
|
||||
|
||||
let app = Router::new()
|
||||
@@ -160,7 +161,7 @@ async fn submit(
|
||||
};
|
||||
|
||||
let _guard = state.file_lock.lock().await;
|
||||
let path = &state.cfg.json_output;
|
||||
let path = &state.output_file;
|
||||
|
||||
let mut existing: Vec<ResponseEntry> = match std::fs::read_to_string(path) {
|
||||
Ok(raw) => serde_json::from_str(&raw).unwrap_or(Vec::new()),
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
|
||||
{% block content %}
|
||||
<div class="form-container">
|
||||
<form action="/submit" method="POST" autocomplete="off">
|
||||
<form action="submit" method="POST" autocomplete="off">
|
||||
{% for f in fields %}
|
||||
{% if f.html_before.is_some() %}
|
||||
{{ f.html_before.as_ref().unwrap() | safe }}
|
||||
|
||||
Reference in New Issue
Block a user