Pages.jl icon indicating copy to clipboard operation
Pages.jl copied to clipboard

Create a CORS example

Open EricForgy opened this issue 7 years ago • 6 comments

EricForgy avatar Feb 03 '18 06:02 EricForgy

Hi, do you have any pointers for this, I need to return an Access-Control-Allow-Origin header.

amanica avatar Aug 10 '18 19:08 amanica

Ok I figured it out:

function addHeaders(res::HTTP.Response)
    push!(res.headers, Pair("Access-Control-Allow-Origin", "*"))
    push!(res.headers, Pair("Content-Type", "application/json"))
    return res
end

Endpoint("/withheadersyeay") do request::HTTP.Request
    if request.method == "GET"
        ret=Dict("some"=>"response data"))
        return addHeaders(HTTP.Response(200, JSON.json(ret)))
    end
    unsupported()
end

amanica avatar Aug 10 '18 22:08 amanica

I can make a pullrequest for this issue if you like. I'm thinking to just add another endpoint to examples/requests.jl with the headers added as above? I really like Pages.jl .

amanica avatar Aug 10 '18 22:08 amanica

finally solved utf-8 encoding problem ( by adding charset as header ) much tnx~

Cyvadra avatar Mar 29 '19 06:03 Cyvadra

Oh wow. I'm sorry @amanica . Somehow I completely missed your comments 😅

EricForgy avatar Mar 29 '19 06:03 EricForgy

No worries, I'm finally busy porting to Julia1 :)

On Fri, 29 Mar 2019, 08:50 Eric Forgy, [email protected] wrote:

Oh wow. I'm sorry @amanica https://github.com/amanica . Somehow I completely missed your comments 😅

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/EricForgy/Pages.jl/issues/11#issuecomment-477888886, or mute the thread https://github.com/notifications/unsubscribe-auth/AAz2qEsp8X96I45p-i7zr26o9snhUKWhks5vbbejgaJpZM4R4Eiv .

amanica avatar Mar 29 '19 07:03 amanica