https://discord.cloudflare.com logo
Join Discord
Powered by
# workers-discussions
  • d

    dave

    02/22/2023, 8:41 PM
    thanks, just ended up adding a counter. Making sure I don't break any anti-spam laws 🙂
  • d

    dave

    02/22/2023, 8:42 PM
    hmm, so after awhile of inactivity, my
    wrangler tail -e production
    seems to stop collecting logs
  • d

    Deleted User

    02/22/2023, 9:12 PM
    I want to purge cache from the Worker Cache API using https://api.cloudflare.com/#zone-purge-files-by-url instead of using
    cache.delete
    since its only per colo. Would this work at all?
    My cache key would be
    https://${url.host}/${key}
    and I'm a little confused if I should purge the cache key or purge the actual endpoint it's hitting which would be something different like
    https://${url.host}/${key}.json
    In my cases it seems to be clearing the cache key that works
  • l

    Louis DCK

    02/22/2023, 9:35 PM
    I'm quite new so for my first project I created a BMI calculator API with Cloudflare Workers (and Hono). For my next project, I would like to create an API that returns something from a database. For example, each time you query the API you get a random fact about cats picked from my cat facts database. Would KV be the best option or are there other better options? Links to guides or tutorials on how to do this would definitely be welcome.
  • m

    muslax

    02/23/2023, 12:04 PM
    I have tested such use case (generate random items from storage) with KV, D1 and DO. And the fastest is consistently DO.
  • r

    renzor

    02/23/2023, 1:56 PM
    hi, I have a miniflare question. My worker will be mounted at
    example.com/api
    . Is there a way to configure miniflare to accept a baseUrl like
    /api
    ?
    Copy code
    // my worker
    import { Hono } from "hono"
    const app = new Hono()
    
    app.get("/", (c) => c.text("Hono!"))
    
    export default app
    Copy code
    // my miniflare dispatch
    const response = await mf.dispatchFetch(
      new URL("https://example.com/api"),
    )
  • r

    renzor

    02/23/2023, 1:56 PM
    how can I make that request hit that api endpoint? It seems like there should be a
    baseUrl
    option to tell miniflare to point
    /api
    requests to my worker, since it will be mounted at
    example.com/api
  • b

    boywithkeyboard

    02/23/2023, 4:43 PM
    that doesn't work like that, @renzor. you need to specify the base path in your hono app!
  • b

    boywithkeyboard

    02/23/2023, 4:45 PM
    because your router (hono in this case) parses the pathname of the incoming request, which starts with the
    /api
    prefix
  • r

    renzor

    02/23/2023, 4:55 PM
    oh i think i see what you mean
  • r

    renzor

    02/23/2023, 4:55 PM
    i was thinking the worker sees a request to
    example.com/api/thing
    as
    /thing
    because its mounted at
    example.com/api
  • s

    Skye

    02/23/2023, 4:55 PM
    You'll need to tell hono that the base path is /api
  • r

    renzor

    02/23/2023, 4:58 PM
    ah nice, ok thanks...maybe like this?
    Copy code
    api.use('/posts/*', cors())
    app.route('/api', api)
    
    export default app
  • s

    Skye

    02/23/2023, 4:59 PM
    something like that would work, yeah
  • s

    Skye

    02/23/2023, 4:59 PM
    it looks like it doesn't have a base path option from the docs - but you could definitely make a feature request for that on the hono repo if you wanted
  • r

    renzor

    02/23/2023, 5:04 PM
    yeah, will do..thanks @Skye and @boywithkeyboard
  • d

    dave

    02/23/2023, 6:32 PM
    Does D1 not work with email Workers...?
  • d

    dave

    02/23/2023, 6:36 PM
    like on the fetch event, my
    D1Database
    var is nowhere on my
    env
    object
  • d

    dave

    02/23/2023, 6:37 PM
    @Chaika did you ever get around to trying emails + D1?
  • s

    Skye

    02/23/2023, 6:38 PM
    Yeah the shim needs to add an email handler
  • c

    Chaika

    02/23/2023, 6:38 PM
    Most I did is emails to discord via webhook. Are you using the latest wrangler version? Afaik d1 is still a bit weird, and requires wrangler since it adds a shim to function
  • s

    Skye

    02/23/2023, 6:38 PM
    cc @rozenmd
  • c

    Chaika

    02/23/2023, 6:38 PM
    oh is that why? rip
  • s

    Skye

    02/23/2023, 6:38 PM
    it's a 1 line code change essentially 😅
  • d

    dave

    02/23/2023, 6:38 PM
    2.10.0
  • d

    dave

    02/23/2023, 6:39 PM
    trying 2.11.0 now
  • d

    dave

    02/23/2023, 6:39 PM
    yep same issue with 2.11.0
  • s

    Skye

    02/23/2023, 6:39 PM
    .
  • s

    Skye

    02/23/2023, 6:39 PM
    It won't work on any version yet
  • s

    Skye

    02/23/2023, 6:40 PM
    But it'll be a very easy fix, and I've already tagged the right person
1...230023012302...2509Latest