WebTemplate is a minimal starter template for rapidly building static websites with a configurable Node.js HTTP server. Just clone, configure, and start developing your website—no frameworks or complex setup required!
- Quick Start: Begin development instantly after cloning.
- Built-in HTTP Server: No external dependencies—runs on Node.js.
- Easy Configuration: Route URLs to files through
config.json
. - Custom Middleware: Add your own logic to the request/response cycle.
- Optional CORS: Toggle CORS support using the configuration file.
- Modern JavaScript: Uses ECMAScript modules (
type: "module"
inpackage.json
).
-
Clone the repository:
git clone https://github.com/andrewfeasel/webtemplate.git cd webtemplate
-
Install Node.js
Ensure you have Node.js installed (https://nodejs.org/). -
Run the server:
node server.js
The server listens on port 8080 by default.
-
Open your site:
Go to http://localhost:8080 in your browser.
server.js
— HTTP server entry point; spawns multiple instances of the server for scalability.server-modules/
-- Contains the code for server instances, and module/utility code.config.json
— Main configuration: set routes and server settings here.package.json
— Declares the project as an ES module and sets the entry point.app/
— Place your HTML, CSS, and JS files here (see route examples inconfig.json
).
All server behavior is controlled in config.json
. Example:
{
"settings": {
"cors": false,
"port": 8080
},
"routes": {
"/": {
"path": "./app/index.html",
"type": "text/html"
},
"/css/style.css": {
"path": "./app/css/style.css",
"type": "text/css"
},
"/js/script.js": {
"path": "./app/js/script.js",
"type": "text/javascript"
}
}
}
- Each key in
"routes"
is a URL path (e.g.,/
,/css/style.css
). - Each value is an object specifying the local file path and its content type.
"cors": true
enables CORS headers for all responses."port": 8080
sets the TCP port to 8080
Middleware functions run before route matching and response.
You can add your own to the middleware
array in server-modules/instance.js
.
Signature:
(req, res) => { /* ... */ }
Example: Built-in ignoreCORS
middleware from server-modules/instance.js
.
- Loads configuration from
config.json
. - Applies middleware functions to each request.
- If a request URL matches a configured route, serves the mapped file.
- Returns 404 for unknown routes.
Add a new entry to "routes"
in config.json
:
"/about": {
"path": "./app/about.html",
"type": "text/html"
}
Edit the "settings"
object in config.json
(e.g., to enable CORS).
MIT
Happy hacking! 🚀