Giter VIP home page Giter VIP logo

Comments (6)

maraisr avatar maraisr commented on July 22, 2024

Hello 👋🏻

if you've got your html files in KV (or r2) you can use this ~>

export async function serve(ns: KV.Namespace, req: Request | `/${string}`): Promise<Response | void> {

and how to use it check this ~>

assets.serve(binding, request);

hope that helps?

from worktop.

lukeed avatar lukeed commented on July 22, 2024

Correct if your HTML is external.

If you want to serve a local HTML file, you can use the worktop.build package and just import the HTML file directly

import { reply } from "worktop/response";
import HOME from "./index.html";

API.add("GET", "/", (req, context) => {
  return reply(200, HOME, {
    "content-type": "text/html; charset=utf-8"
  });
});

then in your type declarations somewhere you do this:

declare module "*.html" {
  const html: string;
  export default html;
}

Hope that helps!

from worktop.

simplenotezy avatar simplenotezy commented on July 22, 2024

@lukeed but how about serving dynamic content that expects a certain extension? E.g.:

 /:fileName[.html]

?

from worktop.

lukeed avatar lukeed commented on July 22, 2024

I don’t understand the question; it’s too vague. You could be asking two or three different things. Wdym?

from worktop.

simplenotezy avatar simplenotezy commented on July 22, 2024

I'd like to use parameterised routing, but only have it match a specific pattern, that is, that the parameter should end on ".html"

from worktop.

lukeed avatar lukeed commented on July 22, 2024

You can do that ::

API.add("GET", "/:file.html", async (req, context) => {
  context.params.file //=> “foobar”
});

// GET /foobar.html

from worktop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.