forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
22 lines (22 loc) · 797 Bytes
/
Copy pathserver.js
File metadata and controls
22 lines (22 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var http = require("http");
var backend = require("@copilotkit/backend");
var port = 4000;
var HEADERS = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, OPTIONS, PUT, PATCH, DELETE",
"Access-Control-Allow-Headers": "X-Requested-With,content-type",
};
var server = http.createServer(function (req, res) {
console.log("got req with method: ".concat(req.method));
// Respond to OPTIONS (preflight) request
if (req.method === "OPTIONS") {
res.writeHead(200, HEADERS);
res.end();
return;
}
var copilotKit = new backend.CopilotBackend();
copilotKit.streamHttpServerResponse(req, res, new backend.OpenAIAdapter({}), HEADERS);
});
server.listen(port, function () {
console.log("Server running at http://localhost:".concat(port, "/"));
});