res.json( count: docs.length, docs ); catch (err) console.error("β Error while listing Docs:", err); res.status(500).json( error: "Failed to fetch Google Docs list", details: err.message ); );
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ // 2οΈβ£ Route: GET /list-docs // Returns a compact JSON array of Google Docs files. // ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ app.get("/list-docs", async (req, res) => try const auth = await getAuthClient(); const drive = google.drive( version: "v3", auth ); Proxy Google Docs List
const app = express(); const PORT = process.env.PORT || 3000; | | /list-docs route | Calls drive
dotenv.config(); // loads .env (optional) | | Morgan logging | Gives you an
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ // Middleware & server start // ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ app.use(morgan("combined")); app.listen(PORT, () => console.log(`π Proxy listening on http://localhost:$PORT`); console.log(`π GET /list-docs β JSON list of Google Docs`); ); | Section | Purpose | |---------|----------| | Auth helper ( getAuthClient ) | Tries a serviceβaccount first (no user interaction). If missing, falls back to an OAuth2 flow that stores the refresh token in oauth-token.json . | | /list-docs route | Calls drive.files.list with a query ( q ) that filters only Google Docs ( mimeType='application/vnd.google-apps.document' ). Returns a trimmed JSON payload (ID, name, timestamps, owner). | | Health check ( /healthz ) | Handy for loadβbalancers or uptime monitors. | | Morgan logging | Gives you an Apacheβstyle access log β useful when the proxy sits behind other services. | 6οΈβ£ Running the proxy # 1οΈβ£ Install dependencies npm install