Is there a way to create a static file via file upload?

For Workes & Pages, what is the name of the domain?

testfunction.pages.dev/index.html

What is the issue or error you’re encountering

I’ve upload a index.html but cloudflare pages droped it to the _worker.js.

What steps have you taken to resolve the issue?

I’ve read this
the code this doc provide use return env.ASSETS.fetch(request); which will be considered as a function request. is there a way to force it to use static request via file uploading?

What are the steps to reproduce the issue?

export default {
  async fetch(request, env, ctx) {
    return new Response(request.url);
  },
};

and a index.html in the same folder.
I don’t know how to use the wrangler cli.and prefer to solve it by file uploading.
when I upload this and it returns https://testfunction.pages.dev/index.html

I’m confused on what specifically you’re trying to do. If you don’t want to invoke a Function and just want to serve e static file, don’t upload a _worker.js, only upload the static files

By default a _worker.js will always run and be served ahead of assets. You can specify paths with _routes.json if you want to filter it down to only run in specific cases

I want to use the js as the backend, which means request by the client side script, which is static in the index.html .

can you give an example? to exclude the index.html from the list that pages drop to the worker.js?
I think the _worker.js can only be placed under the / folder, am I correct, If so,. my index.html also needs to be place under the root.

Alternatively, use a functions directory which automatically creates this file. That requires Wrangler though.

my json

{
   "version": 1,
   "include": ["/*"],
   "exclude": ["/index.html"]
}

my worker

export default {
  async fetch(request, env, ctx) {
    return new Response(request.url);
  },
};

and it still drops to the worker, do you know why?

image

Try making the exclude just ["/"]. These are routing paths, not asset names specifically. The most ccommon use-case is to do something like:

{
   "version": 1,
   "include": ["/*"],
   "exclude": ["/assets/*"]
}

which’ll invoke the worker for everything except files under the assets directory.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.