Skip to content

Commit 6b1720d

Browse files
committed
fix: swap to netlify
1 parent 4b9d306 commit 6b1720d

3 files changed

Lines changed: 21 additions & 40 deletions

File tree

lib/config/env.ts

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,29 @@
11
/**
2-
* Centralized Environment Configuration for Cloudflare Workers
2+
* Centralized Environment Configuration
33
*
44
* This module provides type-safe access to environment variables/secrets.
55
*
6-
* ## How it works:
7-
*
8-
* Both local development and production use the same access pattern:
9-
* `import { env } from 'cloudflare:workers'`
10-
*
11-
* - **Production**: Secrets are set via `wrangler secret put` in CI/CD
12-
* - **Local Dev**: Secrets are loaded from `.dev.vars` by Miniflare
13-
*
14-
* ## Required files:
15-
*
16-
* - `.dev.vars` - Local development secrets (DO NOT COMMIT)
17-
* ```
18-
* DISCOGS_CONSUMER_KEY=your_key
19-
* DISCOGS_CONSUMER_SECRET=your_secret
20-
* ```
21-
*
22-
* - `wrangler.toml` - Non-sensitive env vars in [vars] section
23-
*
24-
* @see https://developers.cloudflare.com/workers/configuration/secrets/
25-
* @see https://developers.cloudflare.com/workers/local-development/environment-variables/
6+
* Adapted for Netlify/Node.js environment.
267
*/
278

28-
import { env as cloudflareEnv } from 'cloudflare:workers';
29-
309
/**
31-
* Type definition for Cloudflare environment bindings.
32-
* Add new secrets/vars here as they are added to the project.
33-
*
34-
* To generate types automatically, run: `nr cf-typegen`
10+
* Type definition for Environment variables.
3511
*/
3612
export interface CloudflareEnv {
3713
// Discogs OAuth credentials
3814
DISCOGS_CONSUMER_KEY?: string;
3915
DISCOGS_CONSUMER_SECRET?: string;
4016

41-
// Environment identifier (set in wrangler.toml [env.*.vars])
17+
// Environment identifier
4218
ENVIRONMENT?: 'development' | 'staging' | 'production';
4319
}
4420

4521
/**
46-
* Get the typed Cloudflare environment object.
47-
*
48-
* @returns The environment bindings from Cloudflare Workers runtime
22+
* Get the environment object.
23+
* In Node.js/Netlify, this comes from process.env
4924
*/
5025
export function getCloudflareEnv(): CloudflareEnv {
51-
return cloudflareEnv as CloudflareEnv;
26+
return (typeof process !== 'undefined' ? process.env : {}) as unknown as CloudflareEnv;
5227
}
5328

5429
/**
@@ -93,5 +68,5 @@ export function hasDiscogsCredentials(): boolean {
9368
* @returns 'development', 'staging', or 'production'
9469
*/
9570
export function getEnvironment(): CloudflareEnv['ENVIRONMENT'] {
96-
return getEnvVar('ENVIRONMENT') as CloudflareEnv['ENVIRONMENT'];
71+
return (getEnvVar('ENVIRONMENT') as CloudflareEnv['ENVIRONMENT']) || 'development';
9772
}

netlify.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[build]
2+
command = "pnpm build"
3+
publish = "dist"
4+
5+
[[redirects]]
6+
from = "/*"
7+
to = "/index.html"
8+
status = 200

vite.config.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { defineConfig } from 'vite';
22
import { tanstackStart } from '@tanstack/react-start/plugin/vite';
3-
import { cloudflare } from '@cloudflare/vite-plugin';
43
import viteReact from '@vitejs/plugin-react';
54
import tsconfigPaths from 'vite-tsconfig-paths';
65
import tailwindcss from '@tailwindcss/vite';
@@ -10,18 +9,17 @@ export default defineConfig({
109
port: 1995,
1110
},
1211
plugins: [
13-
cloudflare({ viteEnvironment: { name: 'ssr' } }),
14-
tailwindcss(),
15-
tsconfigPaths({
16-
projects: ['./tsconfig.json'],
17-
ignoreConfigErrors: true,
18-
}),
1912
tanstackStart({
2013
srcDirectory: '.',
2114
router: {
2215
routesDirectory: 'app',
2316
},
2417
}),
18+
tailwindcss(),
19+
tsconfigPaths({
20+
projects: ['./tsconfig.json'],
21+
ignoreConfigErrors: true,
22+
}),
2523
viteReact(),
2624
],
2725
ssr: {

0 commit comments

Comments
 (0)