urania-dev / snapp

Yet Another Url Shortner. A simple excercise to learn Svelte.
https://snapp.li
MIT License
210 stars 11 forks source link

Composer file with volume mount for db.sqlite #50

Closed acseven closed 1 month ago

acseven commented 1 month ago

Hi,

I'm trying to try out snapp but I'm having issues with logging in, and it seems that the database isn't getting populated with data, I can't seem to find what I'm doing wrong here.

Here's what I have in the composer file (Portainer):

version: '3.9'
services:
  snapp-url-short:
   image: uraniadev/snapp:latest
   ports:
    - 43000:3000
   volumes:
     - /docker/tools-prod-snapp-url-short/v/db/db.sqlite:/app/prisma/db.sqlite
   environment:
    NODE_ENV: development
    DATABASE_URL: "file:./db.sqlite"
    DATABASE_PROVIDER: sqlite # mysql | sqlite | pg
    TOKEN_SECRET: [>REDACTED<] # openssl rand -base64 32
    ORIGIN: https://url.[>REDACTED<]
    TIMEZONE: Europe/London

    #DATABASE_POSTGRES_URL= # "postgresql://root:password@postgres:5432/snappdb"
    #DATABASE_MYSQL_URL= # "mysql://root:password@mariadb:3306/snappdb"

    ADMIN_USERNAME: [>REDACTED<] # must be specified on first launch as it initiate the database
    ADMIN_EMAIL: [>REDACTED<] # must be specified on first launch as it initiate the database
    ADMIN_PASSWORD: [>REDACTED<] # must be specified on first launch as it initiate the database
    PORT: 3000 # app port
    #PUBLIC_UMAMI_WEBSITE_ID: # uuid  #https://github.com/umami-software/umami
    #PUBLIC_UMAMI_WEBSITE_URL: # https://umami.example.com/script.js
    DISABLE_HOME: false
    ENABLE_SIGNUP: false
    VTAPI_KEY: [>REDACTED<] # VIRUSTOTAL API KEY
    SMTP_HOST: [>REDACTED<] # host smtp.example.com
    SMTP_USER: [>REDACTED<] # info@example.com
    SMTP_PASS: "[>REDACTED<]" # account password
    SMTP_FROM: [>REDACTED<] # no-reply@example.com
    SMTP_PORT: 465 # 465
    SMTP_SSL: true # true

I've created an empty db.sqlite file on the volume location.

The logs state:

Prisma schema loaded from prisma/sqlite/schema.prisma
✔ Generated Prisma Client (v5.18.0) to ./node_modules/@prisma/client in 326ms
Start by importing your Prisma Client (See: http://pris.ly/d/importing-client)
Tip: Want to react to database changes in your app as they happen? Discover how with Pulse: https://pris.ly/tip-1-pulse
npm notice
npm notice New minor version of npm available! 10.8.2 -> 10.9.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.9.0
npm notice To update run: npm install -g npm@10.9.0
npm notice
Prisma schema loaded from prisma/sqlite/schema.prisma
Datasource "db": SQLite database "db.sqlite" at "file:./db.sqlite"
1 migration found in prisma/migrations
No pending migrations to apply.
-------------------------------------------
             Welcome to Snapp!
-------------------------------------------
      Thank you for choosing this app.
      Have a great day and enjoy your
            experience with us!
-------------------------------------------
Listening on 0.0.0.0:3000

While trying to login the console reads:

Failed to load resource: the server responded with a status of 403 (Forbidden)

What could be wrong here?

urania-dev commented 1 month ago

i have to update the docs, it is not clear enough, and there's a typo.

sqlite db is in database_schema folder, so /prisma/sqlite/db.sqlite, try to mount it that way

   - /docker/tools-prod-snapp-url-short/v/db/db.sqlite:/app/prisma/sqlite/db.sqlite

edit: sorry my mistake, i closed the issue clicking on the wrong button. let me know if it is ok now :)

acseven commented 1 month ago

Hi, thanks for the reply. That did solve the db.sqlite issue which now has content.

However, I'm still unable to login with the ADMIN_USERNAME and ADMIN_PASSWORD environment credentials, or with admin/password if those are unset. The browser console reads the following errors (I've tried both using direct IP access and a local UPN via Nginx):

s01

Container logs don't point to anything abnormal:

Prisma schema loaded from prisma/sqlite/schema.prisma
✔ Generated Prisma Client (v5.18.0) to ./node_modules/@prisma/client in 310ms
Start by importing your Prisma Client (See: http://pris.ly/d/importing-client)
Tip: Curious about the SQL queries Prisma ORM generates? Optimize helps you enhance your visibility: https://pris.ly/tip-2-optimize
npm notice
npm notice New minor version of npm available! 10.8.2 -> 10.9.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.9.0
npm notice To update run: npm install -g npm@10.9.0
npm notice
Prisma schema loaded from prisma/sqlite/schema.prisma
Datasource "db": SQLite database "db.sqlite" at "file:./db.sqlite"
1 migration found in prisma/migrations
Applying migration `20240808202925_init`
The following migration(s) have been applied:
migrations/
  └─ 20240808202925_init/
    └─ migration.sql

All migrations have been successfully applied.
-------------------------------------------
             Welcome to Snapp!
-------------------------------------------
      Thank you for choosing this app.
      Have a great day and enjoy your
            experience with us!
-------------------------------------------
Listening on 0.0.0.0:3000
VirusTotal API Key: configuration added to the database.
SMPT Setup: configuration added to the database.

What could be wrong?

Edit: that's a minor typo in the last log line "SMPT" instead of "SMTP", right?

urania-dev commented 1 month ago

you should use the same ORIGIN as ENV, the console log of your screen seems to redirect to http://snapp.-----.local, while your docker compsoe is https://url.

if using it on http:// remember env NODE_ENV to development try to match those two :)

edit: thanks for the typo i'll add that to the next release :)

acseven commented 1 month ago

Thank you, that was it. I was [stupidly] expecting to be able to have an external URL set for the actual shortened URLs while only having local access to the dashboard. My apologies!

Thank you for this tool, it's looking great! If I may add some suggestions for future additions:

urania-dev commented 1 month ago

Actually you can, i never thought of it cause i prefer send my password through https, but if you mean to access it through VPN or in secure way, well it must match origin: .local

the get call for taking the url and redirecting (the frontend final use) can happen via https:// anyway, it doesn't use auth or stuff like that

i'm not sure about security thou.

OAUTH i think would require a privacy policy and can't be compliant with gdpr as cookieless authentication, i preferred keeping it simple.

On prevent admin deleting, well have to be honest happened to me too and i thought i fix'd it. i'll look into thaat

acseven commented 1 month ago

On prevent admin deleting, well have to be honest happened to me too and i thought i fix'd it. i'll look into thaat

Thanks, so you understand the nuisance 😅

Actually you can, i never thought of it cause i prefer send my password through https, but if you mean to access it through VPN or in secure way, well it must match origin: .local

the get call for taking the url and redirecting (the frontend final use) can happen via https:// anyway, it doesn't use auth or stuff like that

I'm not sure I understood, but having unencrypted local access isn't a big deal in my case, but I do want the generated URLs to be available on the internet! Meaning having the ui on snapp.mylan.local and urls accessible on *.urls.mydomain.com, hence preventing public access to the UI.

urania-dev commented 1 month ago

so it should work as long as ORIGIN is the domain of the endpoint you want to login at :)