Gemini AI commited on
Commit
f9686da
·
1 Parent(s): 8659830

feat: Add Node.js static file server and update package.json

Browse files
Files changed (2) hide show
  1. package.json +22 -0
  2. serve.js +22 -0
package.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "localm",
3
+ "version": "1.0.1",
4
+ "description": "",
5
+ "main": "chat-full.js",
6
+ "scripts": {
7
+ "start": "node serve.js",
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/oyin-bo/localm.git"
13
+ },
14
+ "keywords": [],
15
+ "author": "",
16
+ "license": "ISC",
17
+ "type": "commonjs",
18
+ "bugs": {
19
+ "url": "https://github.com/oyin-bo/localm/issues"
20
+ },
21
+ "homepage": "https://github.com/oyin-bo/localm#readme"
22
+ }
serve.js ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const http = require('http'), fs = require('fs'), path = require('path');
2
+
3
+ http.createServer((req, res) => {
4
+ const file = '.' + (req.url === '/' ? '/index.html' : req.url);
5
+
6
+ fs.readFile(file, (err, data) => {
7
+ if (err) {
8
+ res.writeHead(404);
9
+ return res.end(String(err));
10
+ }
11
+
12
+ const ext = path.extname(file);
13
+ const contentType = {
14
+ '.html': 'text/html',
15
+ '.js': 'text/javascript',
16
+ '.css': 'text/css'
17
+ }[ext] || 'text/plain';
18
+
19
+ res.writeHead(200, { 'Content-Type': contentType });
20
+ res.end(data);
21
+ });
22
+ }).listen(8000, () => console.log('Serving on port 8000'));