OxygenFramework / Oxygen.jl

💨 A breath of fresh air for programming web apps in Julia
https://oxygenframework.github.io/Oxygen.jl/
MIT License
383 stars 25 forks source link

missing .js file in a compiled app #127

Closed YuliyaCl closed 9 months ago

YuliyaCl commented 9 months ago

Hi I've compiled a server app with Oxygen.jl in deps (using PackageCompiler.jl, create_app). On the same machine everyting works correctly. But on the another it fails when I'm trying to open docs-page (http://loacalhost:8080/docs) with an error, which related with a missing file:

 Error: ERROR:
│   exception =
│    SystemError: opening file "C:\\Users\\yzh\\.julia\\packages\\Oxygen\\WbJI1\\data\\swagger@4.14.0\\swagger-ui-bundle.js": No such file or directory
│    Stacktrace:
│      [1] systemerror(p::String, errno::Int32; extrainfo::Nothing)
│        @ Base .\error.jl:176
│      [2] #systemerror#82
│        @ .\error.jl:175 [inlined]
│      [3] systemerror
│        @ .\error.jl:175 [inlined]
│      [4] open(fname::String; lock::Bool, read::Nothing, write::Nothing, create::Nothing, truncate::Nothing, append::Nothing)
│        @ Base .\iostream.jl:293
│      [5] open
│        @ .\iostream.jl:275 [inlined]
│      [6] readstaticfile
│        @ C:\Users\yzh\.julia\packages\Oxygen\WbJI1\src\autodoc.jl:426 [inlined]
│      [7] swaggerhtml()
│        @ Oxygen.Core.AutoDoc C:\Users\yzh\.julia\packages\Oxygen\WbJI1\src\autodoc.jl:436
│      [8] #47
│        @ C:\Users\yzh\.julia\packages\Oxygen\WbJI1\src\core.jl:570 [inlined]
│      [9] (::Oxygen.Core.var"#36#43"{Oxygen.Core.var"#47#49"})(req::HTTP.Messages.Request)
│        @ Oxygen.Core C:\Users\yzh\.julia\packages\Oxygen\WbJI1\src\core.jl:539
│     [10] (::HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing})(req::HTTP.Messages.Request)
│        @ HTTP.Handlers C:\Users\yzh\.julia\packages\HTTP\Y2JKB\src\Handlers.jl:439
│     [11] (::Oxygen.Core.var"#29#32"{HTTP.Messages.Request, HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}})()
│        @ Oxygen.Core C:\Users\yzh\.julia\packages\Oxygen\WbJI1\src\core.jl:315
│     [12] handlerequest(getresponse::Oxygen.Core.var"#29#32"{HTTP.Messages.Request, HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}}, catch_errors::Bool)
│        @ Oxygen.Core C:\Users\yzh\.julia\packages\Oxygen\WbJI1\src\core.jl:290
│     [13] #28
│        @ C:\Users\yzh\.julia\packages\Oxygen\WbJI1\src\core.jl:314 [inlined]
│     [14] |>(x::HTTP.Messages.Request, f::Oxygen.Core.var"#28#31"{HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}, Bool})
│        @ Base .\operators.jl:907
│     [15] (::Oxygen.Core.AutoDoc.var"#2#4"{Oxygen.Core.var"#28#31"{HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}, Bool}, HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}, Vector{Any}})(req::HTTP.Messages.Request)
│        @ Oxygen.Core.AutoDoc C:\Users\yzh\.julia\packages\Oxygen\WbJI1\src\autodoc.jl:200
│     [16] #6
│        @ C:\Users\yzh\.julia\packages\Oxygen\WbJI1\src\core.jl:108 [inlined]
│     [17] (::HTTP.Handlers.var"#1#2"{Oxygen.Core.var"#6#8"{Oxygen.Core.AutoDoc.var"#2#4"{Oxygen.Core.var"#28#31"{HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}, Bool}, HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}, Vector{Any}}, Sockets.IPv4}})(stream::HTTP.Streams.Stream{HTTP.Messages.Request, HTTP.Connections.Connection{Sockets.TCPSocket}})
│        @ HTTP.Handlers C:\Users\yzh\.julia\packages\HTTP\Y2JKB\src\Handlers.jl:58
│     [18] (::Oxygen.Core.var"#9#10"{Oxygen.Core.AutoDoc.var"#2#4"{Oxygen.Core.var"#28#31"{HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}, Bool}, HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}, Vector{Any}}})(stream::HTTP.Streams.Stream{HTTP.Messages.Request, HTTP.Connections.Connection{Sockets.TCPSocket}})
│        @ Oxygen.Core C:\Users\yzh\.julia\packages\Oxygen\WbJI1\src\core.jl:123
│     [19] #invokelatest#2
│        @ .\essentials.jl:816 [inlined]
│     [20] invokelatest
│        @ .\essentials.jl:813 [inlined]
│     [21] handle_connection(f::Function, c::HTTP.Connections.Connection{Sockets.TCPSocket}, listener::HTTP.Servers.Listener{Nothing, Sockets.TCPServer}, readtimeout::Int64, access_log::Function)
│        @ HTTP.Servers C:\Users\yzh\.julia\packages\HTTP\Y2JKB\src\Servers.jl:447
│     [22] macro expansion
│        @ C:\Users\yzh\.julia\packages\HTTP\Y2JKB\src\Servers.jl:385 [inlined]
│     [23] (::HTTP.Servers.var"#16#17"{Oxygen.Core.var"#9#10"{Oxygen.Core.AutoDoc.var"#2#4"{Oxygen.Core.var"#28#31"{HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}, Bool}, HTTP.Handlers.Router{typeof(HTTP.Handlers.default404), typeof(HTTP.Handlers.default405), Nothing}, Vector{Any}}}, HTTP.Servers.Listener{Nothing, Sockets.TCPServer}, Set{HTTP.Connections.Connection}, Int64, Oxygen.Core.var"#18#19", Base.Semaphore, HTTP.Connections.Connection{Sockets.TCPSocket}})()
│        @ HTTP.Servers .\task.jl:514
└ @ Oxygen.Core C:\Users\yzh\.julia\packages\Oxygen\WbJI1\src\core.jl:292

The issue is close to that one https://github.com/GenieFramework/SwaggerMarkdown.jl/issues/8

It may be also solved by using RelocatableFolders.jl package. Add to the src/autodoc.jl constant, estimated with a @path macro (I've tested it in a dev mode)

using RelocatableFolders
const DATA_PATH = @path abspath(joinpath(@__DIR__, "..", "data"))

And use the constant inside the function:

function readstaticfile(filepath::String) :: String 
    path = joinpath(DATA_PATH, filepath) 
    return read(open(path), String)
end
ndortega commented 9 months ago

Hi @YuliyaCl,

These are my favorite types of issues: concise, well-researched, and include a solution. Thanks for taking the time to point this out! This change will go out in version 1.2 tonight