Fiber: 馃 Ability to use tls through autocert?

Created on 2 Mar 2020  路  3Comments  路  Source: gofiber/fiber

Question description

I do not have certificate files, but have Let's Encrypt
What I need to host on https with tls?

Most helpful comment

Hi @Terisback v1.8.2 will support custom TLS configs

package main

import (
    "crypto/tls"
    "github.com/gofiber/fiber"
)

func main() {
    app := fiber.New()

    app.Get("/", func(c *fiber.Ctx) {
        c.Send(c.Protocol()) // => https
    })

    cer, err := tls.LoadX509KeyPair("certs/ssl.cert", "certs/ssl.key")
    if err != nil {
                log.Fatal(err)
    }
    config := &tls.Config{Certificates: []tls.Certificate{cer}}

    // Start server with https/ssl enabled
    app.Listen(443, config)
}

All 3 comments

According to use inside FastHttp, I believe that you can be based on e.g. below:

I saw these two examples:
https://github.com/valyala/fasthttp/issues/167
https://github.com/valyala/fasthttp/issues/431

Tnx, I'll see tomorrow morning

Hi @Terisback v1.8.2 will support custom TLS configs

package main

import (
    "crypto/tls"
    "github.com/gofiber/fiber"
)

func main() {
    app := fiber.New()

    app.Get("/", func(c *fiber.Ctx) {
        c.Send(c.Protocol()) // => https
    })

    cer, err := tls.LoadX509KeyPair("certs/ssl.cert", "certs/ssl.key")
    if err != nil {
                log.Fatal(err)
    }
    config := &tls.Config{Certificates: []tls.Certificate{cer}}

    // Start server with https/ssl enabled
    app.Listen(443, config)
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jeyraj picture jeyraj  路  4Comments

petersephrin picture petersephrin  路  4Comments

faultable picture faultable  路  3Comments

koddr picture koddr  路  4Comments

abowloflrf picture abowloflrf  路  4Comments