Skip to content

Commit 3b35087

Browse files
authored
ports 8000 -> 8001 (#141)
1 parent 6fd450a commit 3b35087

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

typescript/packages/collectathon/chrome-extension/popup.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const API_URL = 'http://localhost:8000';
1+
const API_URL = 'http://localhost:8001';
22
let clipContent = null;
33

44
chrome.runtime.connect({name: "popup"});
@@ -46,7 +46,7 @@ document.addEventListener('DOMContentLoaded', () => {
4646
chrome.tabs.query({active: true, currentWindow: true}, async function(tabs) {
4747
const currentUrl = tabs[0].url;
4848
// Load recent collections
49-
fetch(`http://localhost:8000/suggested-collections?url=${encodeURIComponent(currentUrl)}`)
49+
fetch(`${API_URL}/suggested-collections?url=${encodeURIComponent(currentUrl)}`)
5050
.then(response => response.json())
5151
.then(collections => {
5252
recentCollections.innerHTML = '<h3>Suggested Collections</h3>' +
@@ -63,7 +63,7 @@ document.addEventListener('DOMContentLoaded', () => {
6363
searchInput.addEventListener('input', () => {
6464
const query = searchInput.value;
6565
if (query) {
66-
fetch(`http://localhost:8000/search-collections?q=${encodeURIComponent(query)}`)
66+
fetch(`${API_URL}/search-collections?q=${encodeURIComponent(query)}`)
6767
.then(response => response.json())
6868
.then(collections => {
6969
let resultsHtml = '<h3>Search Results</h3>';
@@ -118,7 +118,7 @@ document.getElementById('clipButton').addEventListener('click', () => {
118118
const url = clipContent ? clipContent.pageUrl : tabs[0].url;
119119
const content = clipContent || { type: 'webpage', url: url };
120120

121-
fetch('http://localhost:8000/clip', {
121+
fetch(`${API_URL}/clip`, {
122122
method: 'POST',
123123
headers: {
124124
'Content-Type': 'application/json',

typescript/packages/collectathon/server.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { addRule, applyRules, deleteRule, listRules } from "./rules.ts";
2323
import { search } from "./search.ts";
2424
import { handleActionCommand } from "./action.ts";
2525
import { handleDreamCommand } from "./dream.ts";
26-
import { handleViewCommand } from "./view.ts";
2726
const app = new Application();
2827
const router = new Router();
2928

@@ -313,9 +312,26 @@ router.put("/collections/:name/view/:viewId", async (ctx) => {
313312
app.use(router.routes());
314313
app.use(router.allowedMethods());
315314

315+
export const PORT = 8001;
316+
let server;
317+
316318
export async function start() {
317-
console.log("Server running on http://localhost:8001");
318-
await app.listen({ port: 8001 });
319+
console.log(`Server running on http://localhost:${PORT}`);
320+
server = await app.listen({ port: PORT });
321+
}
322+
323+
function shutdown() {
324+
console.log("Shutting down server...");
325+
if (server) {
326+
server.close();
327+
console.log("Server shut down successfully");
328+
}
329+
Deno.exit(0);
330+
}
331+
332+
if (Deno) {
333+
Deno.addSignalListener("SIGINT", shutdown);
334+
Deno.addSignalListener("SIGTERM", shutdown);
319335
}
320336

321337
if (import.meta.main) {

typescript/packages/collectathon/view.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { db } from "./db.ts";
22
import { chat, grabHtml } from "./llm.ts";
33
import { CoreMessage } from "npm:ai@3.3.21";
44
import { open } from "https://deno.land/x/open@v0.0.5/index.ts";
5+
import { PORT } from "./server.ts";
56

67
export const views = new Map<string, string>();
78

@@ -85,7 +86,7 @@ export async function handleViewCommandSingleShot(collection: string, prompt: st
8586
[viewId, collection, html]
8687
);
8788

88-
const url = `http://localhost:8000/view/${collection}/${viewId}`;
89+
const url = `http://localhost:${PORT}/view/${collection}/${viewId}`;
8990
console.log(`Opening view in browser: ${url}`);
9091
await open(url);
9192

@@ -129,7 +130,7 @@ export async function handleViewCommandUpdate(viewId: string, newPrompt: string)
129130
[html, viewId]
130131
);
131132

132-
const url = `http://localhost:8000/view/${collection}/${viewId}`;
133+
const url = `http://localhost:${PORT}/view/${collection}/${viewId}`;
133134
console.log(`Updated view. Opening in browser: ${url}`);
134135
await open(url);
135136
}

0 commit comments

Comments
 (0)