forked from QwikDev/qwik
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add vanilla node server (QwikDev#4699)
- Loading branch information
1 parent
75058cb
commit c2d679e
Showing
4 changed files
with
86 additions
and
0 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,12 @@ | ||
## Node Server | ||
|
||
This app has a minimal zero-dependencies server. Using the built-in `http.createServer` API. | ||
This should be faster and less overhead than Express or other frameworks. | ||
|
||
After running a full build, you can preview the build using the command: | ||
|
||
``` | ||
npm run serve | ||
``` | ||
|
||
Then visit [http://localhost:8080/](http://localhost:8080/) |
15 changes: 15 additions & 0 deletions
15
starters/adapters/node-server/adapters/node-server/vite.config.ts
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,15 @@ | ||
import { nodeServerAdapter } from "@builder.io/qwik-city/adapters/node-server/vite"; | ||
import { extendConfig } from "@builder.io/qwik-city/vite"; | ||
import baseConfig from "../../vite.config"; | ||
|
||
export default extendConfig(baseConfig, () => { | ||
return { | ||
build: { | ||
ssr: true, | ||
rollupOptions: { | ||
input: ["src/entry.node-server.tsx", "@qwik-city-plan"], | ||
}, | ||
}, | ||
plugins: [nodeServerAdapter({ name: "node-server" })], | ||
}; | ||
}); |
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,23 @@ | ||
{ | ||
"description": "Vanilla Node server", | ||
"scripts": { | ||
"build.server": "vite build -c adapters/node-server/vite.config.ts", | ||
"serve": "node server/entry.node-server" | ||
}, | ||
"__qwik__": { | ||
"priority": 19, | ||
"displayName": "Adapter: Node.js Server", | ||
"docs": [ | ||
"https://qwik.builder.io/deployments/node/" | ||
], | ||
"nextSteps": { | ||
"title": "Next Steps", | ||
"lines": [ | ||
" Now you can build a production-ready node app:", | ||
"", | ||
" - pnpm run build: production build", | ||
" - pnpm run serve: runs the production server locally" | ||
] | ||
} | ||
} | ||
} |
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,36 @@ | ||
/* | ||
* WHAT IS THIS FILE? | ||
* | ||
* It's the entry point for the Express HTTP server when building for production. | ||
* | ||
* Learn more about Node.js server integrations here: | ||
* - https://qwik.builder.io/docs/deployments/node/ | ||
* | ||
*/ | ||
import { createQwikCity } from "@builder.io/qwik-city/middleware/node"; | ||
import qwikCityPlan from "@qwik-city-plan"; | ||
import render from "./entry.ssr"; | ||
import { manifest } from "@qwik-client-manifest"; | ||
import { createServer } from "node:http"; | ||
|
||
// Allow for dynamic port | ||
const PORT = process.env.PORT ?? 3004; | ||
|
||
// Create the Qwik City express middleware | ||
const { router, notFound, staticFile } = createQwikCity({ | ||
render, | ||
qwikCityPlan, | ||
manifest, | ||
}); | ||
|
||
const server = createServer(); | ||
|
||
server.on("request", (req, res) => { | ||
staticFile(req, res, () => { | ||
router(req, res, () => { | ||
notFound(req, res, () => {}); | ||
}); | ||
}); | ||
}); | ||
|
||
server.listen(PORT); |