Skip to content

Commit

Permalink
fix: add vanilla node server (QwikDev#4699)
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat authored Jul 3, 2023
1 parent 75058cb commit c2d679e
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
12 changes: 12 additions & 0 deletions starters/adapters/node-server/README.md
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 starters/adapters/node-server/adapters/node-server/vite.config.ts
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" })],
};
});
23 changes: 23 additions & 0 deletions starters/adapters/node-server/package.json
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"
]
}
}
}
36 changes: 36 additions & 0 deletions starters/adapters/node-server/src/entry.node-server.tsx
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);

0 comments on commit c2d679e

Please sign in to comment.