denoland / fresh

The next-gen web framework.
https://fresh.deno.dev
MIT License
12.18k stars 623 forks source link

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

Closed rojvv closed 3 months ago

rojvv commented 6 months ago

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

Should this be public?

deer commented 6 months ago

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?

rojvv commented 6 months ago

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 commented 6 months ago

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

deer commented 6 months ago

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.

rojvv commented 6 months ago

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.

marvinhagemeister commented 3 months ago

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

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