-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
25 changed files
with
416 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/node_modules/ | ||
/dist/ |
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,8 @@ | ||
export const runtime = 'edge' | ||
|
||
// Import the built server entry from dist, so import.meta.env and other Vite features | ||
// are available in the server entry (Vite already processed this file) | ||
import fetch from '../dist/server/index.mjs' | ||
|
||
export const GET = fetch | ||
export const POST = fetch |
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,20 @@ | ||
{ | ||
"scripts": { | ||
"dev": "vite dev", | ||
"build": "vite build", | ||
"prod": "cross-env NODE_ENV=production node dist/server/index.mjs" | ||
}, | ||
"dependencies": { | ||
"@vitejs/plugin-react": "^4.3.1", | ||
"hono": "^4.5.5", | ||
"@hono/node-server": "^1.12.0", | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1", | ||
"vike": "^0.4.181", | ||
"vike-node": "^0.1.9", | ||
"vike-react": "^0.4.18", | ||
"vite": "^5.3.5", | ||
"cross-env": "^7.0.3" | ||
}, | ||
"type": "module" | ||
} |
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,70 @@ | ||
export { Layout } | ||
|
||
import React from 'react' | ||
import './Layout.css' | ||
|
||
function Layout({ children }) { | ||
return ( | ||
<PageLayout> | ||
<Sidebar> | ||
<a className="navitem" href="/"> | ||
Pre-rendered | ||
</a> | ||
<a className="navitem" href="/dynamic"> | ||
Dynamic | ||
</a> | ||
<a className="navitem" href="/static"> | ||
Static | ||
</a> | ||
</Sidebar> | ||
<Content>{children}</Content> | ||
</PageLayout> | ||
) | ||
} | ||
|
||
function PageLayout({ children }) { | ||
return ( | ||
<div | ||
style={{ | ||
display: 'flex', | ||
maxWidth: 900, | ||
margin: 'auto' | ||
}} | ||
> | ||
{children} | ||
</div> | ||
) | ||
} | ||
|
||
function Sidebar({ children }) { | ||
return ( | ||
<div | ||
style={{ | ||
padding: 20, | ||
paddingTop: 42, | ||
flexShrink: 0, | ||
display: 'flex', | ||
flexDirection: 'column', | ||
alignItems: 'center', | ||
lineHeight: '1.8em' | ||
}} | ||
> | ||
{children} | ||
</div> | ||
) | ||
} | ||
|
||
function Content({ children }) { | ||
return ( | ||
<div | ||
style={{ | ||
padding: 20, | ||
paddingBottom: 50, | ||
borderLeft: '2px solid #eee', | ||
minHeight: '100vh' | ||
}} | ||
> | ||
{children} | ||
</div> | ||
) | ||
} |
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 @@ | ||
export { config } | ||
|
||
import vikeReact from 'vike-react/config' | ||
|
||
const config = { | ||
// https://vike.dev/extends | ||
extends: vikeReact, | ||
prerender: false | ||
} |
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,14 @@ | ||
body { | ||
margin: 0; | ||
font-family: sans-serif; | ||
} | ||
* { | ||
box-sizing: border-box; | ||
} | ||
a { | ||
text-decoration: none; | ||
} | ||
|
||
.navitem { | ||
padding: 3px; | ||
} |
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,27 @@ | ||
export default Page | ||
|
||
import React, { useState } from 'react' | ||
|
||
function Page() { | ||
return ( | ||
<> | ||
<h1>Welcome</h1> | ||
This page is: | ||
<ul> | ||
<li>Dynamic</li> | ||
<li>No static html generated</li> | ||
<li>Interactive</li> | ||
</ul> | ||
<Counter /> | ||
</> | ||
) | ||
} | ||
|
||
function Counter() { | ||
const [count, setCount] = useState(0) | ||
return ( | ||
<button type="button" onClick={() => setCount((count) => count + 1)}> | ||
Counter {count} | ||
</button> | ||
) | ||
} |
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,27 @@ | ||
export default Page | ||
|
||
import React, { useState } from 'react' | ||
|
||
function Page() { | ||
return ( | ||
<> | ||
<h1>Welcome</h1> | ||
This page is: | ||
<ul> | ||
<li>Pre-rendered</li> | ||
<li>Static html generated</li> | ||
<li>Interactive</li> | ||
</ul> | ||
<Counter /> | ||
</> | ||
) | ||
} | ||
|
||
function Counter() { | ||
const [count, setCount] = useState(0) | ||
return ( | ||
<button type="button" onClick={() => setCount((count) => count + 1)}> | ||
Counter {count} | ||
</button> | ||
) | ||
} |
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,3 @@ | ||
export default { | ||
prerender: true | ||
} |
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,27 @@ | ||
export default Page | ||
|
||
import React, { useState } from 'react' | ||
|
||
function Page() { | ||
return ( | ||
<> | ||
<h1>Welcome</h1> | ||
This page is: | ||
<ul> | ||
<li>Pre-rendered</li> | ||
<li>Static html generated</li> | ||
<li>Not interactive (no javascript is downloaded for this page)</li> | ||
</ul> | ||
<Counter /> | ||
</> | ||
) | ||
} | ||
|
||
function Counter() { | ||
const [count, setCount] = useState(0) | ||
return ( | ||
<button type="button" onClick={() => setCount((count) => count + 1)}> | ||
Counter {count} | ||
</button> | ||
) | ||
} |
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,10 @@ | ||
// https://vike.dev/render-modes#html-only | ||
|
||
export default { | ||
prerender: true, | ||
meta: { | ||
Page: { | ||
env: { server: true, client: false } | ||
} | ||
} | ||
} |
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,14 @@ | ||
Minimal example of using `vike-node` and `vike-react`. | ||
|
||
```bash | ||
git clone [email protected]:vikejs/vike-node | ||
cd vike-node/examples/hono-react-vercel-edge/ | ||
npm install | ||
npm run dev | ||
``` | ||
|
||
## One-Click Deploy | ||
|
||
Deploy the example using [Vercel](https://vercel.com): | ||
|
||
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/vikejs/vike-node/tree/main/examples/hono-react-vercel-edge&project-name=hono-react&repository-name=hono-react) |
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,21 @@ | ||
import { serve } from '@hono/node-server' | ||
import { Hono } from 'hono' | ||
import vike from 'vike-node/hono' | ||
|
||
export default startServer() | ||
|
||
function startServer() { | ||
const app = new Hono() | ||
app.use(vike()) | ||
const port = process.env.PORT || 3000 | ||
serve( | ||
{ | ||
fetch: app.fetch, | ||
port: +port, | ||
// Needed for Bun | ||
overrideGlobalObjects: false | ||
}, | ||
() => console.log(`Server running at http://localhost:${port}`) | ||
) | ||
return app.fetch | ||
} |
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 @@ | ||
{ | ||
"outputDirectory": "dist/client", | ||
"rewrites": [ | ||
{ | ||
"source": "/((?!assets/).*)", | ||
"destination": "/api" | ||
} | ||
] | ||
} |
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 react from '@vitejs/plugin-react' | ||
import vike from 'vike/plugin' | ||
import vikeNode from 'vike-node/plugin' | ||
|
||
export default { | ||
plugins: [react(), vike({ prerender: true }), vikeNode('server/index.js')] | ||
} |
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
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
Oops, something went wrong.