Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

depfree: replace cors dep in scaffold templates with inline CORS middleware

Adam Eivy075c22046115
diff --git a/PLAN.md b/PLAN.md
index 2d8f26de3a..1f611f3add 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -83,7 +83,7 @@ For project goals, see [GOALS.md](./GOALS.md). For completed work, see [DONE.md]
- [ ] **PREREQ: Sync lock files** — Run `npm install` in root, `server/`, and `client/` after pinning exact versions to eliminate `invalid` warnings in `npm ls`
- [ ] **`uuid`** — Add `server/lib/uuid.js` (`export const uuidv4 = () => crypto.randomUUID()`), update 40 import paths. Trivial. ~5 lines.
-- [ ] **`cors`** — Replace `cors({ origin: true, credentials: true })` in `server/index.js` and 3x `cors()` in `server/routes/scaffold.js` with inline `setCorsHeaders` middleware (~15 lines). Remove direct dep. Note: package remains in lock file via socket.io.
+- [x] **`cors`** — Replaced `cors()` in scaffold.js generated templates with inline CORS middleware; removed `cors` from generated package.json deps. PortOS itself already used inline headers. Note: package remains in lock file via socket.io.
- [ ] **`axios`** — Write `server/lib/httpClient.js` (fetch-based client factory with `AbortSignal.timeout`, query param serialization). Update `services/jira.js`, `services/datadog.js`, and `services/datadog.test.js`. Inline token-expiry interceptor logic in jira.js. ~60 lines.
- [ ] **`multer`** — Write `server/lib/multipart.js` (stream multipart to disk, size limit, MIME filter, req.file compatible). Update `routes/appleHealth.js`. ~65 lines.
- [ ] **`node-telegram-bot-api`** — Write `server/lib/telegramClient.js` (fetch-based Telegram Bot API wrapper: polling loop with offset, `getMe`, `sendMessage`, `editMessageText`, `answerCallbackQuery`, `stopPolling`, regex handler dispatch). Update `services/telegram.js`. ~110 lines.
diff --git a/server/routes/scaffold.js b/server/routes/scaffold.js
index 57e91c11b8..724a04af52 100644
--- a/server/routes/scaffold.js
+++ b/server/routes/scaffold.js
@@ -295,12 +295,17 @@ async function scaffoldApp(req, res) {
await ensureDir(serverDir);
await writeFile(join(serverDir, 'index.js'), `import express from 'express';
-import cors from 'cors';
const app = express();
const PORT = process.env.PORT || ${apiPort || 3001};
-app.use(cors());
+app.use((req, res, next) => {
+ res.set('Access-Control-Allow-Origin', '*');
+ res.set('Access-Control-Allow-Methods', 'GET,POST,PUT,PATCH,DELETE,OPTIONS');
+ res.set('Access-Control-Allow-Headers', 'Content-Type,Authorization');
+ if (req.method === 'OPTIONS') return res.sendStatus(204);
+ next();
+});
app.use(express.json());
app.get('/api/health', (req, res) => {
@@ -318,7 +323,6 @@ app.listen(PORT, '0.0.0.0', () => {
const pkg = safeJSONParse(pkgContent, { dependencies: {}, devDependencies: {}, scripts: {} });
pkg.dependencies = pkg.dependencies || {};
pkg.dependencies.express = '^4.21.2';
- pkg.dependencies.cors = '^2.8.5';
pkg.scripts['server'] = 'node server/index.js';
pkg.scripts['dev:all'] = 'concurrently "npm run dev" "npm run server"';
pkg.devDependencies = pkg.devDependencies || {};
@@ -338,19 +342,23 @@ app.listen(PORT, '0.0.0.0', () => {
start: 'node index.js'
},
dependencies: {
- express: '^4.21.2',
- cors: '^2.8.5'
+ express: '^4.21.2'
}
};
await writeFile(join(repoPath, 'package.json'), JSON.stringify(pkg, null, 2));
await writeFile(join(repoPath, 'index.js'), `import express from 'express';
-import cors from 'cors';
const app = express();
const PORT = process.env.PORT || ${apiPort || 3000};
-app.use(cors());
+app.use((req, res, next) => {
+ res.set('Access-Control-Allow-Origin', '*');
+ res.set('Access-Control-Allow-Methods', 'GET,POST,PUT,PATCH,DELETE,OPTIONS');
+ res.set('Access-Control-Allow-Headers', 'Content-Type,Authorization');
+ if (req.method === 'OPTIONS') return res.sendStatus(204);
+ next();
+});
app.use(express.json());
app.get('/api/health', (req, res) => {
@@ -976,7 +984,6 @@ export default function AIProvidersPage() {
'test:watch': 'vitest'
},
dependencies: {
- 'cors': '^2.8.5',
'express': '^4.21.2',
'portos-ai-toolkit': '^0.1.0',
'socket.io': '^4.8.3',
@@ -990,7 +997,6 @@ export default function AIProvidersPage() {
// === Server index.js ===
await writeFile(join(serverDir, 'index.js'), `import express from 'express';
-import cors from 'cors';
import { createServer } from 'http';
import { Server } from 'socket.io';
import { createAIToolkit } from 'portos-ai-toolkit/server';
@@ -1003,7 +1009,13 @@ const io = new Server(httpServer, {
const PORT = process.env.PORT || ${apiPort || 3001};
-app.use(cors());
+app.use((req, res, next) => {
+ res.set('Access-Control-Allow-Origin', '*');
+ res.set('Access-Control-Allow-Methods', 'GET,POST,PUT,PATCH,DELETE,OPTIONS');
+ res.set('Access-Control-Allow-Headers', 'Content-Type,Authorization');
+ if (req.method === 'OPTIONS') return res.sendStatus(204);
+ next();
+});
app.use(express.json());
// Initialize AI Toolkit with routes for providers, runs, and prompts