https://discord.cloudflare.com logo
Join Discord
Powered by
# functions
  • m

    micromashor

    05/25/2023, 4:43 PM
    sounds good
  • s

    Skye

    05/25/2023, 4:43 PM
    You could also (as of wrangler 3) use a
    _worker.js
    directory instead, where the
    _worker.js/index.js
    file is your normal worker, and anything in that directory isn't uploaded as a static asset
  • s

    Skye

    05/25/2023, 4:44 PM
    This isn't for the functions folder - this is using a
    _worker.js
    file which is a little different
  • m

    micromashor

    05/25/2023, 4:44 PM
    is that a wrangler feature or a feature of Pages? I'm not using wrangler
  • s

    Skye

    05/25/2023, 4:44 PM
    @Walshy | Pages does the CI have wrangler 3 yet
  • w

    Walshy | Pages

    05/25/2023, 4:45 PM
    we have not gone to wrangler 3 yet no
  • s

    Skye

    05/25/2023, 4:45 PM
    Ah, unfortunate. can't do that for now without pages publish then
  • w

    Walshy | Pages

    05/25/2023, 4:45 PM
    the _worker.js exists before wrangler 3 though
  • w

    Walshy | Pages

    05/25/2023, 4:45 PM
    but we don't document that haha
  • s

    Skye

    05/25/2023, 4:45 PM
    not the folder (in a working state)
  • w

    Walshy | Pages

    05/25/2023, 4:45 PM
    yeah ok, a fix may have been in 3
  • m

    micromashor

    05/25/2023, 4:46 PM
    is there a way I can tell what version of wrangler the CI is using?
  • s

    Skye

    05/25/2023, 4:46 PM
    I'd just go with this for now
  • m

    micromashor

    05/25/2023, 4:46 PM
    yeah that sounds good
  • w

    Walshy | Pages

    05/25/2023, 4:46 PM
    we're using 2.20.0
  • m

    micromashor

    05/25/2023, 4:47 PM
    ah ok
  • m

    micromashor

    05/25/2023, 5:22 PM
    I'm now getting a build error after assets are published:
    Copy code
    Error: Failed to publish your Function. Got error: multipart uploads must contain a readable body_part or main_module
  • l

    Lloyd

    05/26/2023, 1:56 PM
    Are there any types available? I don't want them to be
    any
    for this typescript middleware
    Copy code
    ts
    const abTest = async ({ request, next, env }) => {
      const url = new URL(request.url)
      // if homepage
      if (url.pathname === "/") {
  • l

    Lloyd

    05/26/2023, 1:56 PM
    there's no
    Middleware
    types that I can see
  • k

    kian

    05/26/2023, 2:00 PM
    Middleware is no different to a normal Functions context, is it?
  • l

    Lloyd

    05/26/2023, 2:01 PM
    Ah ok, so
    const abTest: PagesFunction = async ({ request, next, env }) => {
    is valid?
  • u

    Unsmart | Tech debt

    05/26/2023, 2:01 PM
    Yeah it should be
  • l

    Lloyd

    05/26/2023, 2:01 PM
    nice :)#
  • l

    Lloyd

    05/26/2023, 2:01 PM
    🙂
  • e

    ehesp

    05/26/2023, 4:02 PM
    I'm really losing faith in being able to deploy to pages. I have a Remix app which regularly throws the
    Failed to publish your Function. Got error: Error: Script startup exceeded CPU time limit.
    error. I've tried to dynamic import everything where possible outside of the global scope, but this error frequently comes up on deployments... but randomly also works with no changes. It's becoming so regular that we're struggling to deploy changes without constant redeployment attempts. Lots of Googling really doesn't help, there just seems to be no way to debug or profile the code to identify where the issue lies 😦
  • l

    Lloyd

    05/26/2023, 4:43 PM
    Are there special rules around redirects to other domains? Nothing happens when the redirect is called? This is a middleware.
    Copy code
    ts
    const exampleShortenedUrls: ShortenedUrl[] = [
        { id: '2tg9xy3', url: 'https://example.com' },
        { id: '3f2tqv', url: 'https://en.wikipedia.org/wiki/Example.com' },
        { id: '48difn', url: 'www.google.com' },
    ];
    
    ...
    
        const { pathname } = new URL(request.url);
        const id = new URL(request.url).pathname.startsWith('/')
            ? pathname.slice(1)
            : pathname;
    
        const matchedUrl = exampleShortenedUrls.find((entry) => entry.id === id);
    
        if (!matchedUrl) {
            console.warn('Unable to find shortened URL', id);
        } else {
            console.info('Found shortened URL and redirecting user', id);
            Response.redirect(matchedUrl.url, 302);  // this does nothing?
        }
    
        return next();
    Copy code
    "logs": [
        {
          "message": [
            "Found shortened URL and redirecting user",
            "2tg9xy3"
          ],
          "level": "info",
          "timestamp": 1685119189434
        }
      ],
  • e

    Erisa | Support Engineer

    05/26/2023, 4:44 PM
    When you say it does nothing... what is returned to the client? Does it fall through to the
    next()
    , return an empty response or something else?
  • l

    Lloyd

    05/26/2023, 4:45 PM
    the normal root of the page eg /
  • e

    Erisa | Support Engineer

    05/26/2023, 4:45 PM
    Oh I see now
  • e

    Erisa | Support Engineer

    05/26/2023, 4:45 PM
    You do
    Response.redirect
    but you don't return it
1...388389390391392Latest