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

App is not linked on Cloudflare Workers #438

Open
Ernxst opened this issue May 17, 2024 · 0 comments · May be fixed by #439
Open

App is not linked on Cloudflare Workers #438

Ernxst opened this issue May 17, 2024 · 0 comments · May be fixed by #439
Assignees

Comments

@Ernxst
Copy link
Contributor

Ernxst commented May 17, 2024

Resource.App does not currently work on Cloudflare Workers. Using 0.0.364 with the following worker script and config:

// functions/worker.ts
import { Resource } from "sst";

export default {
  async fetch(request, env) {
    return Response.json({ stage: Resource.App.stage })
  }
} satisfies ExportedHandler
// sst.config.ts
/// <reference path="./.sst/platform/config.d.ts" />

export default $config({
	app(input) {
		return {
			name: "ion",
			removal: input.stage === "production" ? "retain" : "remove",
			home: "cloudflare",
			version: "0.0.364"
		};
	},
	async run() {
		const worker = new sst.cloudflare.Worker(
			"MyFunction",
			{
				handler: "./functions/worker.ts",
				url: true,
			}
		);

		return {
			url: worker.url,
		}
	},
});

Invoking the worker throws a Cloudflare error. Examining the log stream in the Cloudflare dashboard shows the following exception:

  "exceptions": [
    {
      "stack": "    at Object.get (worker.mjs:57:11)\n    at fetch (worker.mjs:64:44)\n    at Object.fetch (worker.mjs:41:14)",
      "name": "Error",
      "message": "\"App\" is not linked",
      "timestamp": 1715985053747
    }
  ],

Upon further investigation, going to the worker in the Cloudflare dashboard then to the Variables tab shows:

image

Then, a quick look in sdk/js/src/resource.ts#L27 shows it populates the key from the Cloudflare env as-is without stripping the SST_RESOURCE_ prefix like it does when reading from process.env on line 16.

@Ernxst Ernxst linked a pull request May 17, 2024 that will close this issue
@thdxr thdxr self-assigned this May 20, 2024
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

Successfully merging a pull request may close this issue.

2 participants