-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver-esm.js
More file actions
30 lines (25 loc) · 792 Bytes
/
server-esm.js
File metadata and controls
30 lines (25 loc) · 792 Bytes
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
30
'use strict'
import http from 'http';
import fs from 'fs';
const port = process.env.PORT || 3001;
const server = http.createServer((req,res)=>{
if(req.url==='/'){
res.writeHead(200,{'Content-Type':'text/html'});
res.write('<h1>Hello World</h1>');
}
else{
if(req.url==='/api/sessions'){
const sessions = fs.readdirSync(new URL("./sessions.json",import.meta.url),'utf-8');
res.writeHead(200,{'Content-Type':'application/json'});
res.write(sessions);
}
else{
res.writeHead(404,{'Content-Type':'text/plain'})
res.write(`404: Not found - ${req.url}`);
}
}
res.end();
});
server.listen(port,()=>{
console.log(`Server is running on http://localhost:${port}`);
})