fresh icon indicating copy to clipboard operation
fresh copied to clipboard

Add a way for plug-ins to know whether the app is run from dev.ts

Open rojvv opened this issue 1 year ago • 5 comments

https://github.com/denoland/fresh/blob/e3508c30541018e6384ce8b373baf17d3dc52673/src/server/context.ts#L148

Should this be public?

rojvv avatar Mar 14 '24 01:03 rojvv

Check out https://github.com/search?q=repo%3Adenoland%2Ffresh%20deno_deployment_id&type=code

Currently fresh just looks for this environment variable. Could you you do the same in your plugin?

deer avatar Mar 14 '24 02:03 deer

Not all servers are deployed on Deno Deploy. I want a built-in alternative to Deno.mainModule.endsWith("dev.ts"). This is already there in the server context I guess, but it is a private property: #dev.

rojvv avatar Mar 14 '24 02:03 rojvv

I updated the title and the description to precisely describe the issue.

rojvv avatar Mar 14 '24 02:03 rojvv

Thanks, that makes sense. But FYI https://fresh.deno.dev/docs/concepts/deployment#docker. It's important to set that environment variable, if you're not running on deploy.

Exposing the internal dev flag is probably more clear.

deer avatar Mar 14 '24 02:03 deer

Actually, this also makes sense for the end user’s side (like the developer working on the routes, not the user visiting the website). Some logic might be production-only or vice-versa.

rojvv avatar Mar 19 '24 00:03 rojvv

In Fresh 2 plugins have access to the Fresh config object.

// Logs: "development" or "production
console.log(app.config.mode)

marvinhagemeister avatar Jun 05 '24 08:06 marvinhagemeister