Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to use both svelte-kit dev and wrangler pages dev? #7

Closed
lmaccherone opened this issue Jan 2, 2022 · 7 comments
Closed

Comments

@lmaccherone
Copy link

I'd love to be able to use both svelte-kit dev and wrangler pages dev. I've tried

wrangler pages dev ./.svelte-kit/cloudflare -- svelte-kit dev

but that doesn't proxy the assets or the api correctly.

I'm about to try to launch them separately and sense that the cloudflare services are local, but I thought I'd ask first here in case someone has already figured this out.

@lukeed
Copy link
Owner

lukeed commented Jan 2, 2022

Check out the dev branch: https://github.com/lukeed/pages-fullstack/tree/dev

it was the best melded solution I could come up with

@lmaccherone
Copy link
Author

Cool. Do you just use npm run dev or do you first do npm run watch, then npm run dev?

@lukeed
Copy link
Owner

lukeed commented Jan 2, 2022

It’s watch only. Not the same DX as dev but it gets the job done. Use dev for quick development for things like ui/styling and then watch to make sure it actually works lol. It’s kinda rough hence not being main branch

@lmaccherone
Copy link
Author

I'll give it a try and at least provide feedback. Thanks.

@lukeed
Copy link
Owner

lukeed commented Jan 2, 2022

Np, closing as there's not much else that can be done here w/o directly affecting either tool

@lukeed lukeed closed this as completed Jan 2, 2022
@lmaccherone
Copy link
Author

Finally got around to trying this but can't figure out how to expose KV and Durable Object namespaces to my endpoints and test them locally. Any help would be appreciated.

@colinhowells
Copy link

colinhowells commented Mar 26, 2022

There's some recent discussion but the local dev story isn't looking great

I think you could use the API when local and grab stuff that way, maybe

At least I can now get at KV when in Pages – I think some things needed to get sorted first:

/**
 * @type {import('@sveltejs/kit').RequestHandler}
 */
export async function get({ params, platform }) {
	
	let yerData = null;
	let someOtherDataObject = {};
	let KV = null;

	// https://github.com/sveltejs/kit/tree/master/packages/adapter-cloudflare#environment-variables
	if (platform?.env?.YOUR_KV_NAMESPACE) {
		KV = platform.env.YOUR_KV_NAMESPACE;
		yerData = await KV.get('some_sort_of_key'); // returns null if ain't none
	}

	if (yerData) {
		someOtherDataObject = someMagic(yerData);
	}

	if (KV && someOtherDataObject) {
		KV.put('some_other_key_maybe', JSON.stringify(someOtherDataObject), { expirationTtl: 2629746 }); // 1 month expiration
	}

	return {
		body: someOtherDataObject,
	};
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants