-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpico-jarvis.js
More file actions
26 lines (24 loc) · 900 Bytes
/
pico-jarvis.js
File metadata and controls
26 lines (24 loc) · 900 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
const fs = require('fs');
const http = require('http');
function handler(request, response) {
const { url } = request;
console.log(`Handling ${url}...`);
if (url === '/health') {
response.writeHead(200).end('OK');
} else if (url === '/' || url === '/index.html') {
response.writeHead(200, { 'Content-Type': 'text/html' });
response.end(fs.readFileSync('./index.html'));
} else if (url.startsWith('/chat')) {
const parsedUrl = new URL(`http://localhost/${url}`);
const { search } = parsedUrl;
const question = decodeURIComponent(search.substring(1));
const answer = 'Yo man';
console.log({ question, answer });
response.writeHead(200).end(answer);
} else {
console.error(`${url} is 404!`)
response.writeHead(404);
response.end();
}
}
http.createServer(handler).listen(5000);