Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection timeout / endless loading with API starter template #1213

Open
LimpidCrypto opened this issue Jan 24, 2025 · 1 comment
Open

Connection timeout / endless loading with API starter template #1213

LimpidCrypto opened this issue Jan 24, 2025 · 1 comment

Comments

@LimpidCrypto
Copy link
Contributor

LimpidCrypto commented Jan 24, 2025

Description

I've started a new project using the API template and added a new model and controller. Now I wanted to start the app with cargo loco start. I tried to test the connection with curl localhost:5150/_ping -v --max-time 10 and it timed out. No other route works, it always times out.

To Reproduce

  1. loco new
    1. Rest API template
    2. postgres database
  2. cargo loco generate model projects name:string! description:string
  3. cargo loco db migrate
  4. cargo loco db enity
  5. cargo loco generate controller projects --api
  6. adjust the generated controllers index function:
#![allow(clippy::missing_errors_doc)]
#![allow(clippy::unnecessary_struct_initialization)]
#![allow(clippy::unused_async)]
use axum::debug_handler;
use loco_rs::prelude::*;

use crate::models::_entities::projects;

#[debug_handler]
pub async fn index(State(ctx): State<AppContext>) -> Result<Response> {
    let all_projects = projects::Entity::find().all(&ctx.db).await?;
    format::json(all_projects)
}

pub fn routes() -> Routes {
    Routes::new().prefix("api/projects/").add("/", get(index))
}
  1. cargo loco start
  2. try to reach any route

Expected Behavior

I expect loco to give me ANY response.

Environment:

Additional Context

I also tried other ports and tried to reach the database via the playground which succeeded. It seems to be an issue with the server.

@kaplanelad
Copy link
Contributor

kaplanelad commented Jan 26, 2025

I couldn’t reproduce the issue you mentioned. Here are the steps I followed:

Created a new project:

❯ loco new
✔ ❯ App name? · myapp  
✔ ❯ What would you like to build? · Rest API (with DB and user auth)  
✔ ❯ Select a DB Provider · Postgres  
✔ ❯ Select your background worker type · Async (in-process tokio async task) 

Generated the model:

cargo loco generate model projects name:string! description:string
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 5.70s
     Running `target/debug/myapp-cli generate model projects 'name:string!'' 'description:string'`
added: "migration/src/m20250126_083848_projects.rs"
...
... Done.
2025-01-26T08:38:59.723544Z  WARN app: loco_rs::boot:  environment=development
* Migration for `projects` added! You can now apply it with `$ cargo loco db migrate`.
* A test for model `Projects` was added. Run with `cargo test`.
* 
*

Then, I added the index function to the controllers, and everything worked as expected.

Could you share a repository or code snippet so I can take a closer look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants