jkwchui

jkwchui

I have a simple LiveView app that

  1. write user input to a temporary markup file (content.typ),
  2. drops to System.cmd/2 to process this markup with a CLI (typst), and
  3. deliver the output (content.png) to the client

In dev, I specify the path for the temporary files as

Application.app_dir(:typeset, "priv/static/uploads/")

and this works on my machine™.


I then have this dockerized and deployed on Fly, copying the Typst CLI to /bin and verified the CLI works by ssh in.

However, the temp files are now written to a directory that does not exist.

** (File.Error) could not write to file "/app/_build/prod/lib/typeset/priv/static/uploads/content.typ"

What is the proper way of handling temporary files, to be processed with a CLI, when deploying?

Showing Posts 1 to 9

jkwchui

jkwchui OP

Thank you @LostKobrakai.

For future readers: you’d use System.tmp_dir/0 for the path. So if you want to write a content.png, it would go to

File.write!(
  System.tmp_dir() <> "/content.png",
  your_content_here
)

You can tell Phoenix to serve these as static files by adding a plug in MyAppWeb.Endpoint immediately after the only Plug.Static:

plug Plug.Static,
  at: "/",
  from: :my_app,
  gzip: false,
  only: MyAppWeb.static_paths()

# 👇 ADD THIS
plug Plug.Static,
  at: System.tmp_dir(),
  from: System.tmp_dir()
LostKobrakai

LostKobrakai

Giving people access to all your system tmp files is not a good idea. You want to scope this to a nested folder for your application.

jkwchui

jkwchui OP

This is a follow-up question on static files.

I have now deployed the little LiveView (on Fly: Typeset · Phoenix Framework) and on its own it’s all dandy. The plan was to make this into an iFrame embed in Wordpress, so this follows the recipe How to: Embed a LiveView via iframe and goes through its own pipeline.

I mapped this to a custom domain: Typeset · Phoenix Framework and the same app falls apart with this error:

Cookie “__phoenix_reload_status__” does not have a proper “SameSite” attribute value. Soon, cookies without the “SameSite” attribute or with an invalid value will be treated as “Lax”. This means that the cookie will no longer be sent in third-party contexts. If your application depends on this cookie being available in such contexts, please add the “SameSite=None“ attribute to it. To know more about the “SameSite“ attribute, read https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie/SameSite

__phoenix_reload_status__ is part of Phoenix.LiveView.Static, but I don’t understand why this is causing an issue only when it’s visited on the custom domain. There is a separate socket with its own @session_options

  @embed_session_options [
    store: :cookie,
    key: "_typeset_key",
    signing_salt: "xxxxxxx",
    same_site: "None; Secure"
  ]

and this should be very permissive?

EDIT: this is about check_origin, related to: Phoenix LiveView constantly refreshes with custom domain - Phoenix - Fly.io

Hermanverschooten

Hermanverschooten

I am also using Typst in a couple of projects, that’s why I assembled a Hex package that uses a Rust nif so you don’t have to shell out, or use a temporary file.

D4no0

D4no0

Is the rust API you are using public?

From the documentation it seems like typst was designed as a self-contained product rather than a rust library (even if implemented in rust).

Hermanverschooten

Hermanverschooten

jkwchui

jkwchui OP

Thanks — I did check out ex_typst. I shell out (necessitating the temporary file) because I’m using the CLI to generate transparent PNGs, and also (in the future) use typst query from the CLI to extract parameters from the run.

(It was a while since I did the earlier expts; with the PDF, the only way I can get a clean transparent PNG back out was to Mogrify it with peculiar flags… again from the CLI.)

Hermanverschooten

Hermanverschooten

:+1:

Each case is different.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews