-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f28acce
commit 53c8f88
Showing
33 changed files
with
469 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
declare module '*.html' { | ||
const content: string; | ||
export default content; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
declare module '*.svg' { | ||
const content: string; | ||
export default content; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; | ||
import { NextUIProvider } from "@nextui-org/react"; | ||
import { Outlet } from 'react-router-dom'; | ||
import { Header } from "@/components/Header/Header"; | ||
import { Footer } from "@/components/Footer/Footer"; | ||
const App = () => { | ||
return (_jsx("div", { className: "container", children: _jsxs(NextUIProvider, { children: [_jsx(Header, {}), _jsx(Outlet, {}), _jsx(Footer, {})] }) })); | ||
}; | ||
export default App; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { jsx as _jsx } from "react/jsx-runtime"; | ||
export const Footer = () => (_jsx("footer", { style: { marginTop: "100px", padding: "30px" }, className: 'bg-light', children: "Footer component." })); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; | ||
import { memo, useMemo } from 'react'; | ||
import logoSrc from "@public/images/cloudflare.svg"; | ||
export const Header = memo(() => { | ||
const logo = useMemo(() => logoSrc, []); | ||
return (_jsxs("div", { children: [_jsx("nav", { className: "navbar navbar-light bg-light mb-1", children: _jsxs("div", { className: "container-fluid", style: { height: "50px" }, children: [_jsx("span", { className: "navbar-brand h1", children: "Cloudflare React Worker" }), _jsx("span", { style: { position: "relative", right: 0 }, children: _jsx("img", { src: logo, width: "151", height: "50", alt: "logo" }) })] }) }), _jsx("br", {})] })); | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Router } from 'itty-router'; | ||
import * as routes from "./routers"; | ||
|
||
const router = Router(); | ||
|
||
const { base64Handler, healthHandler, postHandler, rootHandler, routesAndAssetsHandler } = routes; | ||
|
||
/** | ||
* Health route | ||
* This route is used to check the health status of the application. | ||
* When a GET request is made to /health, it will be handled by the healthHandler. | ||
*/ | ||
router.get('/health', healthHandler); | ||
|
||
/** | ||
* Test route for base64 encoding | ||
* This route takes a text parameter and returns its base64 encoded version. | ||
* When a GET request is made to /base64/:text, it will be handled by the base64Handler. | ||
*/ | ||
router.get("/base64/:text", base64Handler); | ||
|
||
/** | ||
* Test POST route | ||
* This route is used to handle POST requests for testing purposes. | ||
* When a POST request is made to /post, it will be handled by the postHandler. | ||
*/ | ||
router.post("/post", postHandler); | ||
|
||
/** | ||
* Catch-all route for serving the React app | ||
* This is the last route we define. It will match any route that hasn't been | ||
* defined above, making it useful as a catch-all route. | ||
* This ensures that any route not explicitly defined will serve the React app, | ||
* allowing the client-side routing of React Router to take over. | ||
*/ | ||
router.all('*', rootHandler); | ||
|
||
/** | ||
* Event listener for incoming requests | ||
* All incoming requests to the worker are passed to the router where your routes | ||
* are called, and the response is sent. The routesAndAssetsHandler will map | ||
* assets and routes accordingly. | ||
*/ | ||
addEventListener('fetch', (event: any) => { | ||
event.respondWith(routesAndAssetsHandler(event, router)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,27 @@ | ||
import { createRoot } from 'react-dom/client'; | ||
import { createBrowserRouter, RouterProvider } from 'react-router-dom' | ||
import App from './App'; | ||
import Error from './pages/Error'; | ||
import Home from '@/pages/Home'; | ||
import './globals.css'; | ||
|
||
const router = createBrowserRouter([ | ||
{ | ||
path: '/', | ||
element: <App/>, | ||
errorElement: <Error/>, | ||
children: [ | ||
{ | ||
index: true, | ||
element: <Home/>, | ||
}, | ||
{ | ||
path: '/test', | ||
element: <h1>Testing 1 2 3</h1>, | ||
}, | ||
], | ||
}, | ||
]); | ||
|
||
// Render your React component instead | ||
const root = createRoot(document.getElementById('root')); | ||
root.render( | ||
<RouterProvider router={ router }/> | ||
); | ||
import { jsx as _jsx } from "react/jsx-runtime"; | ||
import { createRoot } from 'react-dom/client'; | ||
import { createBrowserRouter, RouterProvider } from 'react-router-dom'; | ||
import App from './App'; | ||
import Error from './pages/Error'; | ||
import Home from '@/pages/Home'; | ||
import './globals.css'; | ||
const router = createBrowserRouter([ | ||
{ | ||
path: '/', | ||
element: _jsx(App, {}), | ||
errorElement: _jsx(Error, {}), | ||
children: [ | ||
{ | ||
index: true, | ||
element: _jsx(Home, {}), | ||
}, | ||
{ | ||
path: '/test', | ||
element: _jsx("h1", { children: "Testing 1 2 3" }), | ||
}, | ||
], | ||
}, | ||
]); | ||
// Render your React component instead | ||
const root = createRoot(document.getElementById('root')); | ||
root.render(_jsx(RouterProvider, { router: router })); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { createRoot } from 'react-dom/client'; | ||
import { createBrowserRouter, RouterProvider } from 'react-router-dom' | ||
import App from './App'; | ||
import Error from './pages/Error'; | ||
import Home from '@/pages/Home'; | ||
import './globals.css'; | ||
|
||
const router = createBrowserRouter([ | ||
{ | ||
path: '/', | ||
element: <App/>, | ||
errorElement: <Error/>, | ||
children: [ | ||
{ | ||
index: true, | ||
element: <Home/>, | ||
}, | ||
{ | ||
path: '/test', | ||
element: <h1>Testing 1 2 3</h1>, | ||
}, | ||
], | ||
}, | ||
]); | ||
|
||
// Render your React component instead | ||
// @ts-ignore | ||
const root = createRoot(document.getElementById('root')); | ||
root.render( | ||
<RouterProvider router={router}/> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; | ||
import { Header } from "@/components/Header/Header"; | ||
import { Footer } from "@/components/Footer/Footer"; | ||
const Error = () => { | ||
return (_jsxs("div", { className: "container", children: [_jsx(Header, {}), _jsx("div", { className: "row", children: _jsx("div", { className: "col-12", children: _jsx("h1", { children: "Error!" }) }) }), _jsx(Footer, {})] })); | ||
}; | ||
export default Error; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; | ||
import { useState } from 'react'; | ||
import { Button } from "@nextui-org/react"; | ||
const Home = () => { | ||
const [count, setCount] = useState(0); | ||
const tester = "Victor E"; | ||
return (_jsx("div", { className: "row", children: _jsxs("div", { className: "col-12", children: [_jsx("h1", { children: "Hello, Cloudflare Workers!" }), _jsx("br", {}), _jsx("h3", { children: "This is a basic React page deployed on Cloudflare Workers." }), _jsx("br", {}), _jsxs("pre", { children: [_jsx("strong", { children: "Your name:" }), " ", tester] }), _jsxs("p", { children: ["Count: ", count] }), _jsx("br", {}), _jsx(Button, { color: "primary", type: "button", onClick: () => setCount(count + 1), children: "Increase" })] }) })); | ||
}; | ||
export default Home; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
import { Buffer } from 'buffer'; | ||
|
||
export const base64Handler = async ({ params }) => { | ||
// Decode text like "Hello%20world" into "Hello world" | ||
let input = decodeURIComponent(params.text) | ||
|
||
// Construct a buffer from our input | ||
let buffer = Buffer.from(input, "utf8") | ||
|
||
// Serialise the buffer into a base64 string | ||
let base64 = buffer.toString("base64") | ||
|
||
const backendApi = 'https://6wkf624dt4.execute-api.us-east-1.amazonaws.com/prod/'; | ||
const response = await fetch(backendApi) | ||
const data = await response.json() | ||
|
||
// Return the HTML with the string to the client | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
import { Buffer } from 'buffer'; | ||
export const base64Handler = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params }) { | ||
// Decode text like "Hello%20world" into "Hello world" | ||
let input = decodeURIComponent(params.text); | ||
// Construct a buffer from our input | ||
let buffer = Buffer.from(input, "utf8"); | ||
// Serialise the buffer into a base64 string | ||
let base64 = buffer.toString("base64"); | ||
const backendApi = 'https://6wkf624dt4.execute-api.us-east-1.amazonaws.com/prod/'; | ||
const response = yield fetch(backendApi); | ||
const data = yield response.json(); | ||
// Return the HTML with the string to the client | ||
return new Response(` | ||
<p>Base64 encoding: <code>${base64}</code></p> | ||
<p>${JSON.stringify(data, null, 2)}</p> | ||
`, { | ||
headers: { | ||
"Content-Type": "text/html" | ||
} | ||
}) | ||
}; | ||
`, { | ||
headers: { | ||
"Content-Type": "text/html" | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Buffer } from 'buffer'; | ||
|
||
export const base64Handler = async ({ params }) => { | ||
// Decode text like "Hello%20world" into "Hello world" | ||
let input = decodeURIComponent(params.text) | ||
|
||
// Construct a buffer from our input | ||
let buffer = Buffer.from(input, "utf8") | ||
|
||
// Serialise the buffer into a base64 string | ||
let base64 = buffer.toString("base64") | ||
|
||
const backendApi = 'https://6wkf624dt4.execute-api.us-east-1.amazonaws.com/prod/'; | ||
const response = await fetch(backendApi) | ||
const data = await response.json() | ||
|
||
// Return the HTML with the string to the client | ||
return new Response(` | ||
<p>Base64 encoding: <code>${base64}</code></p> | ||
<p>${JSON.stringify(data, null, 2)}</p> | ||
`, { | ||
headers: { | ||
"Content-Type": "text/html" | ||
} | ||
}) | ||
}; |
Oops, something went wrong.