Skip to content

Commit

Permalink
vercel
Browse files Browse the repository at this point in the history
  • Loading branch information
nitedani committed Aug 6, 2024
1 parent 0b5591e commit 8f64923
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
15 changes: 4 additions & 11 deletions examples/express-react-vercel/api/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import express from 'express'
import vike from 'vike-node/connect'
import { connectToWeb } from 'vike-node'
import app from '../server/index.js'

export default startServer()

function startServer() {
const app = express()
app.use(vike({ static: false }))
const port = process.env.PORT || 3000
app.listen(port, () => console.log(`Server running at http://localhost:${port}`))
return app
}
// Web request handlers support streaming by default on Vercel
export const GET = connectToWeb(app)
6 changes: 5 additions & 1 deletion examples/express-react-vercel/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ npm install
npm run dev
```

https://vercel.com/new/clone?repository-url=https://github.com/vikejs/vike-node/tree/vercel/examples/express-react-vercel&project-name=express-react&repository-name=express-react
## 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/vercel/examples/express-react-vercel&project-name=express-react&repository-name=express-react)
3 changes: 2 additions & 1 deletion examples/express-react-vercel/server/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import express from 'express'
import vike from 'vike-node/connect'

startServer()
export default startServer()

function startServer() {
const app = express()
app.use(vike())
const port = process.env.PORT || 3000
app.listen(port, () => console.log(`Server running at http://localhost:${port}`))
return app
}
8 changes: 7 additions & 1 deletion packages/vike-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
"name": "vike-node",
"version": "0.1.6",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"./connect": "./dist/connect.js",
"./fastify": "./dist/fastify.js",
"./h3": "./dist/h3.js",
"./hono": "./dist/hono.js",
"./elysia": "./dist/elysia.js",
"./plugin": "./dist/plugin/index.js"
"./plugin": "./dist/plugin/index.js",
".": "./dist/index.js"
},
"scripts": {
"dev": "tsc --watch",
Expand Down Expand Up @@ -58,6 +61,9 @@
],
"plugin": [
"./dist/plugin/index.d.ts"
],
".": [
"./dist/index.d.ts"
]
}
},
Expand Down
2 changes: 2 additions & 0 deletions packages/vike-node/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { connectToWeb } from './runtime/adapters/connectToWeb.js'
export { createServerResponse } from './runtime/adapters/createServerResponse.js'
4 changes: 4 additions & 0 deletions packages/vike-node/src/runtime/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ function handleViteDevServer(req: IncomingMessage, res: ServerResponse): Promise
}

function resolveStaticConfig(static_: VikeOptions['static']): false | { root: string; cache: boolean } {
// Disable static file serving for Vercel
// Vercel will serve static files on its own
// See vercel.json > outputDirectory
if (process.env.VERCEL) return false
if (static_ === false) return false
if (static_ === true || static_ === undefined) {
return { root: defaultStaticDir, cache: true }
Expand Down

0 comments on commit 8f64923

Please sign in to comment.