-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathserver.js
More file actions
29 lines (24 loc) · 1.12 KB
/
server.js
File metadata and controls
29 lines (24 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/* Simple Node.js and Express application server for serving static assets.*/
const express = require('express');
const path = require('path');
const port = process.env.PORT || 8080;
const app = express();
// Middleware to serve static files from the 'dist' directory
// This directory should contain the built assets of your application
// Ensure that the 'dist' directory exists and contains your static files.
// You can have subdirectories in 'dist' for better organization.
// For example, you might have 'dist/css', 'dist/js', etc.
// The static files will be served at the root URL (e.g., http://localhost:8080/)
app.use(express.static(__dirname + '/dist'));
// serve index.html for the root path
app.get("/", function (request, response) {
response.sendFile(path.resolve(__dirname, 'index.html'));
});
// example route to demonstrate server functionality
// this can be accessed at http://localhost:8080/hello
// and will respond with "Hello World, from the server!"
app.get("/hello", function (request, response) {
response.send("Hello World, from the server!");
});
app.listen(port);
console.log("server started on port " + port);