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

    harris

    05/26/2023, 10:12 PM
    makes sense, thank you
  • n

    nikivi

    05/26/2023, 11:01 PM
    does this mean my variables i set in dashboard will be overriden? 😨

    https://cdn.discordapp.com/attachments/779390076219686943/1111791260135596042/image.pngâ–¾

  • n

    nikivi

    05/26/2023, 11:01 PM
    my config is just this

    https://cdn.discordapp.com/attachments/779390076219686943/1111791352930381874/image.pngâ–¾

  • s

    Skye

    05/26/2023, 11:02 PM
    You can use
    --keep-vars
    to keep the ones set in the dashboard
  • s

    Skye

    05/26/2023, 11:03 PM
    Or you can put the vars in your wrangler.toml to keep them without needing the flag
  • n

    nikivi

    05/26/2023, 11:03 PM

    https://cdn.discordapp.com/attachments/779390076219686943/1111791712319307846/image.pngâ–¾

  • n

    nikivi

    05/26/2023, 11:03 PM
    is this ok still?
  • n

    nikivi

    05/26/2023, 11:03 PM
    > Or you can put the vars in your wrangler.toml
  • n

    nikivi

    05/26/2023, 11:04 PM
    so i thought about this option although i don't get how to securely have them in the file
  • n

    nikivi

    05/26/2023, 11:04 PM
    via process.env or something perhaps
  • w

    Walshy | Pages

    05/26/2023, 11:06 PM
    If you added secrets, they'll be ok
  • w

    Walshy | Pages

    05/26/2023, 11:06 PM
    If you added normal env vars, you should put them in your wrangler.toml really
  • w

    Walshy | Pages

    05/26/2023, 11:06 PM
    The warning is just there in case you do something destructive. If it was just secrets, you're ok 🙂
  • i

    Iann

    05/27/2023, 1:22 AM
    Thanks I totally missed that, I did manage to find the settings for workers, however I couldn't find Routes for pages or R2, planning on deploying static files that would benefit from the cdn cache.
  • i

    Iann

    05/27/2023, 1:23 AM
    I think I have a workaround which is to monkey patch
    <script>
    on the html
  • c

    Chaika

    05/27/2023, 1:42 AM
    ahh yea you can't do that with Pages or R2, neither work with wildcards like that. You could use a worker fetching from R2 if the extra worker invocation costs don't bother you
  • i

    Iann

    05/27/2023, 1:44 AM
    well yeah the extra invocation cost kinda bother me a bit, but I guess I have no other option, I will just return a minimal html from the worker that contains metadata to monkey patch a
    <script>
    that grabs the static files from
    static.domain.com
    R2
  • r

    REISUB

    05/27/2023, 3:29 AM
    Where can I ask something about Zero Trust?
  • c

    Cyb3r-Jok3

    05/27/2023, 3:35 AM
    #1104040620948992090 or #909458221419356210
  • b

    b-fuze (Mike32)

    05/27/2023, 5:18 AM
    Is it possible to deploy a worker function with
    wrangler
    and then invoke an older deployed version that hasn't been updated to the new code?
  • b

    b-fuze (Mike32)

    05/27/2023, 5:20 AM
    I'm asking because it seems that this has happened to me. If so, I'm curious if there's like a period of time that I should wait before invoking my worker functions to ensure that the new deployment has fully saturated all of the edge locations
  • h

    HardAtWork

    05/27/2023, 5:23 AM
    Unless there is an incident, it should take less than a minute to update everywhere
  • b

    b-fuze (Mike32)

    05/27/2023, 5:24 AM
    Ah, okay, I definitely invoked it a lot faster than that. Thanks
  • z

    zizi

    05/27/2023, 8:36 AM
    hi, I found call
    controller.error
    in method
    write
    for WritableStream will not end stream which causes websocket never close. I tested in Chrome,
    controller.error
    can trigger
    catch
    block.. Below is the sample code for this.
    Copy code
    js
    export default {
        async fetch(request, env, ctx) {
            const upgradeHeader = request.headers.get('Upgrade');
            if (!upgradeHeader || upgradeHeader !== 'websocket') {
                return new Response('not websocket', { status: 200 });
            }
            const webSocketPair = new WebSocketPair();
            const [client, webSocket] = Object.values(webSocketPair);
            webSocket.accept();
            let count = 0;
            const readableStream = new ReadableStream({
                start(controller) {
                    setInterval(() => {
                        controller.enqueue(count);
                        count++;
                    }, 500)
    
                },
                async pull(controller) {
                },
                cancel() {
                    console.log('ReadableStream was canceled.');
                },
            });
    
            const writableStream = new WritableStream({
                write(chunk, controller) {
                    console.log(`Received data: ${chunk}`);
                    webSocket.send(`Received data: ${chunk}`);
                    if (chunk === 3) {
                        controller.error('eroorooororo')
                        return;
                    }
    
                },
                close() {
                    console.log('WritableStream was closed');
                },
                abort() {
                    console.log('WritableStream was aborted');
                }
            });
            readableStream.pipeTo(writableStream).catch((error) => {
                console.log('pipeTo error', error);
                webSocket.close();
            });
            webSocket.addEventListener('close', () => {
                console.log('close');
            });
            return new Response(null, {
                status: 101,
                webSocket: client,
            });
        }
    };
  • b

    b-fuze (Mike32)

    05/27/2023, 2:33 PM
    ```js const [client, webSocket] = Object.values(webSocketPair);```looks like quite a precarious assumption...
  • b

    b-fuze (Mike32)

    05/27/2023, 2:34 PM
    I'm not sure what the properties are, but it'd be much safer to write something like```js const {client, webSocket} = webSocketPair;```
  • b

    b-fuze (Mike32)

    05/27/2023, 2:35 PM
    Wait, the actual CF documentation encourages that... Why 🤔
  • k

    kian

    05/27/2023, 2:38 PM
    The properties are literally keys called 0 and 1 rather than being an array
  • b

    b-fuze (Mike32)

    05/27/2023, 2:40 PM
    Yeah, I just Google'd the for ... in (
    Object.values
    follows the same ordering) sorting algorithm... Turns out it has a special exception for integer-looking keys where it sorts those in ascending order before the named keys... That's... Interesting TIL
  • b

    b-fuze (Mike32)

    05/27/2023, 2:41 PM
    Ignore me. But returning an object instead of an array as well... Interesting design I guess
1...250225032504...2509Latest