wen
wen
Explore posts from servers
CDCloudflare Developers
Created by wen on 8/31/2024 in #workers-help
Cannot access kv namespace
@gwapes
24 replies
CDCloudflare Developers
Created by wen on 8/31/2024 in #workers-help
Cannot access kv namespace
so i should be able to use this?
24 replies
CDCloudflare Developers
Created by wen on 8/31/2024 in #workers-help
Cannot access kv namespace
const hono = require('hono').Hono;
const app = new hono();
const { getConnInfo } = require('hono/cloudflare-workers');
const { cors } = require('hono/cors');

app.use('/*', cors());

app.get('/', (c) => c.text('GET /'));
app.get('/geo/:id', async (c) => {
let data = await c.env.visitor.get(`${c.req.param('id')}`);
console.log(data);
if (!data) {
let req = await fetch(`https://api.gapi.io/?key=[...]&i=${c.req.param('id')}`);
data = await req.json();
await c.env.visitor.put(`${c.req.param('id')}`, JSON.stringify(data), { expirationTtl: 172800 });
} else {
data = JSON.parse(data);
}
return c.json(data);
});
const hono = require('hono').Hono;
const app = new hono();
const { getConnInfo } = require('hono/cloudflare-workers');
const { cors } = require('hono/cors');

app.use('/*', cors());

app.get('/', (c) => c.text('GET /'));
app.get('/geo/:id', async (c) => {
let data = await c.env.visitor.get(`${c.req.param('id')}`);
console.log(data);
if (!data) {
let req = await fetch(`https://api.gapi.io/?key=[...]&i=${c.req.param('id')}`);
data = await req.json();
await c.env.visitor.put(`${c.req.param('id')}`, JSON.stringify(data), { expirationTtl: 172800 });
} else {
data = JSON.parse(data);
}
return c.json(data);
});
24 replies
CDCloudflare Developers
Created by wen on 8/31/2024 in #workers-help
Cannot access kv namespace
ok
24 replies
CDCloudflare Developers
Created by wen on 8/31/2024 in #workers-help
Cannot access kv namespace
@gwapes
24 replies
CDCloudflare Developers
Created by wen on 8/31/2024 in #workers-help
Cannot access kv namespace
im on js not ts... so what what would this be fr js
24 replies
CDCloudflare Developers
Created by wen on 8/31/2024 in #workers-help
Cannot access kv namespace
does this mean that evertime i restart my api the data will be erased ??
24 replies
CDCloudflare Developers
Created by wen on 8/31/2024 in #workers-help
Cannot access kv namespace
also this line
const app = new Hono<{ Bindings: Bindings }>()
const app = new Hono<{ Bindings: Bindings }>()
24 replies
CDCloudflare Developers
Created by wen on 8/31/2024 in #workers-help
Cannot access kv namespace
i got all that by running some wrangler cmds
24 replies
CDCloudflare Developers
Created by wen on 8/31/2024 in #workers-help
Cannot access kv namespace
do i not need the line in wrangler.toml ??
24 replies
CDCloudflare Developers
Created by wen on 8/31/2024 in #workers-help
Cannot access kv namespace
i'll read the docs n lyk if i got problems
24 replies
CDCloudflare Developers
Created by wen on 8/31/2024 in #workers-help
Cannot access kv namespace
i was following a diff page on google
24 replies
CDCloudflare Developers
Created by wen on 8/31/2024 in #workers-help
Cannot access kv namespace
ah...
24 replies
CDCloudflare Developers
Created by wen on 8/31/2024 in #workers-help
Cannot access kv namespace
@Leo
24 replies
CDCloudflare Developers
Created by wen on 8/31/2024 in #workers-help
Cannot access kv namespace
wrangler.toml:
24 replies
CDCloudflare Developers
Created by wen on 8/31/2024 in #workers-help
Cannot access kv namespace
kv_namespaces = [{binding = "visitor", id = "...", preview_id = "..."}]
kv_namespaces = [{binding = "visitor", id = "...", preview_id = "..."}]
24 replies
CDCloudflare Developers
Created by wen on 8/31/2024 in #workers-help
Cannot access kv namespace
app.js:
app.get('/geo/:id', async (c) => {
let data = await env.visitor.get(`${c.req.param('id')}`);
console.log(data);
if (!data) {
let req = await fetch(`https://api.gapi.io/?key=[...]&i=${c.req.param('id')}`);
data = await req.json();
await env.visitor.put(`${c.req.param('id')}`, JSON.stringify(data), { expirationTtl: 172800 });
} else {
data = JSON.parse(data);
}
return c.json(data);
});
app.get('/geo/:id', async (c) => {
let data = await env.visitor.get(`${c.req.param('id')}`);
console.log(data);
if (!data) {
let req = await fetch(`https://api.gapi.io/?key=[...]&i=${c.req.param('id')}`);
data = await req.json();
await env.visitor.put(`${c.req.param('id')}`, JSON.stringify(data), { expirationTtl: 172800 });
} else {
data = JSON.parse(data);
}
return c.json(data);
});
24 replies
CDCloudflare Developers
Created by wen on 8/31/2024 in #workers-help
Cannot access kv namespace
gimme a couple hours i'll get home and send it
24 replies
CDCloudflare Developers
Created by wen on 8/28/2024 in #general-help
Hosting an API
np
52 replies