Intelligence, Advanced Charting & Trading Platform
feat(worker): wire gated v2 REST route to restricted Neon ECB view only
davoodmehraban89 committed
Oct 12, 2026 at 06:26 UTC
f72d1eca091419b916fd33561ca8e09dc7bcdff4
1 file changed
+13
deploy/chartnova/worker.mjs
+13
@@ -1,3 +1,5 @@
1
+import {serveHistoryV2} from "../../packages/market-feed/src/history-api.mjs";
2
+import {buildNeonEcbHistoryLookup} from "../../packages/market-feed/src/neon-ecb-history.mjs";
3
// History is always an ECB daily reference observation, never a candle.
4
// The optional database binding contains a read-only PostgreSQL role and stays server-side.
5
const ECB_SYMBOLS=Object.freeze({EUR_USD_ECB:"USD",EUR_GBP_ECB:"GBP",EUR_CHF_ECB:"CHF"});
@@ -42,6 +44,17 @@ const source=await env.MARKET_CACHE.get(downloadable[url.pathname]);if(!source)r
44
const filename=url.pathname.split("/").at(-1),txt=filename.endsWith(".txt");
45
return new Response(request.method==="HEAD"?null:source,{headers:{"content-type":txt?"text/plain; charset=utf-8":"application/javascript; charset=utf-8","content-disposition":"attachment; filename="+filename,"cache-control":"no-cache","x-content-type-options":"nosniff"}})
46
}
47
+if(url.pathname==="/api/v2/history"){
48
+ // This is a secure opt-in read path. Legacy /api/history stays operational
49
+ // without database credentials and never returns fabricated candles.
50
+ let lookup;
51
+ try{
52
+ lookup=buildNeonEcbHistoryLookup({databaseUrl:env.CHARTNOVA_HISTORY_DATABASE_URL});
53
+ }catch{
54
+ return historyError("history_storage_not_configured",503);
55
+ }
56
+ return serveHistoryV2(request,{lookup});
57
+}
58
if(url.pathname==="/api/history"){
59
if(request.method!=="GET")return historyError("method_not_allowed",405);
60
const allowed=new Set(["symbol","from","to","limit"]);