Register
Register
CDCloudflare Developers
Created by Register on 6/1/2024 in #pages-help
Whats wrong with my wrangler.toml file?
For some reason my D1 database isnt showing up. It does exist but the page function doesnt seem to know about it despite my wrangler.toml file defining it. wrangler.toml
name = "my_app"
compatibility_date = "2023-10-30"
pages_build_output_dir = "./dist"

[[d1_databases]]
binding = "DB"
database_name = "my_app_database"
database_id = "(guid)"
migrations_dir = "sql/migrations"

[vars]
STAGE = "local"

[env.preview.vars]
STAGE = "preview"

[env.production.vars]
STAGE = "production"
name = "my_app"
compatibility_date = "2023-10-30"
pages_build_output_dir = "./dist"

[[d1_databases]]
binding = "DB"
database_name = "my_app_database"
database_id = "(guid)"
migrations_dir = "sql/migrations"

[vars]
STAGE = "local"

[env.preview.vars]
STAGE = "preview"

[env.production.vars]
STAGE = "production"
Function code
import { D1Database } from "@cloudflare/workers-types";
import EventContext from "./EventContext";

class Database {
db: D1Database;

constructor(ctx: EventContext) {
if (!ctx.env.DB) {
console.error("Context environment:", ctx.env);
throw new Error("Database instance is not available in the environment context.");
}
this.db = ctx.env.DB;
}
...
import { D1Database } from "@cloudflare/workers-types";
import EventContext from "./EventContext";

class Database {
db: D1Database;

constructor(ctx: EventContext) {
if (!ctx.env.DB) {
console.error("Context environment:", ctx.env);
throw new Error("Database instance is not available in the environment context.");
}
this.db = ctx.env.DB;
}
...
Exception
"exceptions": [
{
"stack": " at new Database (functionsWorker-0.5557135572831049.js:230:13)\n at onRequestPost2 (functionsWorker-0.5557135572831049.js:388:20)\n at async next (functionsWorker-0.5557135572831049.js:905:26)\n at async Object.fetch (functionsWorker-0.5557135572831049.js:919:14)",
"name": "Error",
"message": "Database instance is not available in the environment context.",
"timestamp": 1717214376469
}
],
"exceptions": [
{
"stack": " at new Database (functionsWorker-0.5557135572831049.js:230:13)\n at onRequestPost2 (functionsWorker-0.5557135572831049.js:388:20)\n at async next (functionsWorker-0.5557135572831049.js:905:26)\n at async Object.fetch (functionsWorker-0.5557135572831049.js:919:14)",
"name": "Error",
"message": "Database instance is not available in the environment context.",
"timestamp": 1717214376469
}
],
Log
{
"message": [
"Context environment:",
{
"ASSETS": {},
"CF_PAGES": "1",
"CF_PAGES_BRANCH": "main",
"CF_PAGES_COMMIT_SHA": "(commit sha)",
"CF_PAGES_URL": "(generated page url)",
"STAGE": "production"
}
],
"level": "error",
"timestamp": 1717214376469
}
{
"message": [
"Context environment:",
{
"ASSETS": {},
"CF_PAGES": "1",
"CF_PAGES_BRANCH": "main",
"CF_PAGES_COMMIT_SHA": "(commit sha)",
"CF_PAGES_URL": "(generated page url)",
"STAGE": "production"
}
],
"level": "error",
"timestamp": 1717214376469
}
7 replies
CDCloudflare Developers
Created by Register on 2/19/2024 in #pages-help
Disable https for specific api routes?
I have an API which a very old game is trying to send data to. This old application (circa 2004) cannot handle HTTPS. It must use HTTP. Is there a way to configure my wrangler.toml to specify specific routes for my Pages project to use HTTP instead of HTTPS?
90 replies
CDCloudflare Developers
Created by Register on 2/5/2024 in #pages-help
How do I invite another dev to my pages dashboard?
No description
6 replies
CDCloudflare Developers
Created by Register on 1/28/2024 in #pages-help
Where do I store SQL migrations in my Pages app's repo?
I am interested to start a new project using Pages but I want to use D1 in this Pages app. I've gone ahead and setup my basic Pages repo where I have a /site directory where I keep my frontend and is what is built when I run npm run build to the /dist directory. And I have my /functions directory which is of course where I am storing my backend API. I am wondering if I should use a /sql directory to house the SQL and migrations? Or should this be kept in a different repo? Main question - how should I be structuring my Pages repo and use/include D1 migrations?
1 replies
CDCloudflare Developers
Created by Register on 1/22/2024 in #workers-help
D1Database JSDoc Reference?
No description
4 replies