Skip to content

Commit 7b1a798

Browse files
committed
Serve static HTML and update index.html
1 parent 9b6a940 commit 7b1a798

2 files changed

Lines changed: 124 additions & 3 deletions

File tree

src/index.html

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Node.js</title>
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<style>
7+
* {
8+
font-family: sans-serif;
9+
font-size: 16px;
10+
}
11+
12+
html,
13+
body {
14+
margin: 0;
15+
min-height: 100vh;
16+
background: #202328;
17+
color: #fff;
18+
}
19+
20+
body {
21+
display: flex;
22+
flex-direction: column;
23+
gap: 8px;
24+
padding: 32px;
25+
align-items: center;
26+
justify-content: center;
27+
box-sizing: border-box;
28+
}
29+
30+
h1 {
31+
font-size: 24px;
32+
}
33+
34+
p,
35+
form,
36+
hr {
37+
max-width: min(400px, 100%);
38+
}
39+
40+
p {
41+
text-align: center;
42+
opacity: 0.8;
43+
line-height: 1.5;
44+
}
45+
46+
button,
47+
.button {
48+
padding: 10px 18px;
49+
align-self: center;
50+
text-decoration: none;
51+
background: #6650fa;
52+
border-radius: 64px;
53+
border: none;
54+
color: #fff;
55+
cursor: pointer;
56+
}
57+
58+
a {
59+
font-size: inherit;
60+
color: inherit;
61+
}
62+
63+
hr {
64+
display: block;
65+
margin: 32px 0;
66+
width: 100%;
67+
height: 2px;
68+
background: #31363f;
69+
border: none;
70+
}
71+
72+
a:last-child {
73+
margin-top: 32px;
74+
}
75+
76+
code {
77+
font-family: monospace;
78+
font-size: 14px;
79+
background: #31363f;
80+
padding: 2px 4px;
81+
border-radius: 4px;
82+
}
83+
</style>
84+
</head>
85+
<body>
86+
<img
87+
alt="Node.js logo"
88+
src="https://github.com/diploi/component-nodejs/raw/main/.diploi/icon.svg"
89+
width="64"
90+
height="64"
91+
/>
92+
93+
<h1>Node.js</h1>
94+
95+
<p>
96+
Your Node.js application is up and running! You can start editing the code
97+
to build your backend API. In development stage, Node.js will
98+
automatically reload as you make changes.
99+
<br /><br />
100+
<b> Install dependencies: </b><br />
101+
Please use <code>npm i package_name</code> to add NPM packages to your
102+
environment.
103+
</p>
104+
105+
<hr />
106+
107+
<a href="https://diploi.com/"
108+
><img width="54" height="16" src="https://diploi.com/logo-white.svg"
109+
/></a>
110+
</body>
111+
</html>

src/index.mjs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
import { createServer } from 'node:http';
1+
import { createServer } from "node:http";
2+
import { readFile } from "node:fs";
3+
import { join } from "node:path";
24

35
const server = createServer((req, res) => {
4-
res.writeHead(200, { 'Content-Type': 'text/plain' });
5-
res.end('Hello World!\n');
6+
const filePath = join(process.cwd(), "src", "index.html");
7+
readFile(filePath, (err, data) => {
8+
if (err) {
9+
res.writeHead(500, { "Content-Type": "text/plain" });
10+
res.end("Error loading HTML file");
11+
return;
12+
}
13+
res.writeHead(200, { "Content-Type": "text/html" });
14+
res.end(data);
15+
});
616
});
717

818
const port = process.env.PORT;

0 commit comments

Comments
 (0)