Open RacerDelux opened 9 hours ago
Hi, are you validating the environment before run app.UseViteDevelopmentServer()
?
That method shouldn't be called in production.
Hi, are you validating the environment before run
app.UseViteDevelopmentServer()
? That method shouldn't be called in production.
This is what is in my program.cs
:
if (app.Environment.IsDevelopment())
{
app.UseWebSockets();
// Use Vite Dev Server as middleware.
app.UseViteDevelopmentServer(true);
}
And this is my Environment setting in the pipeline:
It looks like the error comes right after these NPM scripts are run.
Ahh. I was thinking you were running the Vite dev server but it's not that.
You're creating a HTTPS certificate in your vite.config.ts
like the examples. That's okey while you are developing the app, but it's not even required for production and as I see your pipeline process doesn't allow to create the certificate anyway.
So, the solution is editing your vite.config.ts
to avoid generating the dotnet certificate in production mode and/or remove all of the SSL
configuration for Vite.
Ahh. I was thinking you were running the Vite dev server but it's not that.
You're creating a HTTPS certificate in your
vite.config.ts
like the examples. That's okey while you are developing the app, but it's not even required for production and as I see your pipeline process doesn't allow to create the certificate anyway.So, the solution is editing your
vite.config.ts
to avoid generating the dotnet certificate in production mode and/or remove all of theSSL
configuration for Vite.
Don't I need that for development? If so is it possible to pass through the environment variable and skip making the cert?
The certificate is only required if you want/need to use https
for both ASP.NET
and Vite
during development and use the same dev certificate. If that's not the case, you can work without SSL.
And as you said, you can also use environment variables to skip the cert in your vite.config.ts
by reading the environment variable via process.env.MY_VARIABLE
.
And as you said, you can also use environment variables to skip the cert in your
vite.config.ts
by reading the environment variable viaprocess.env.MY_VARIABLE
.
This worked great! Do you think it would be good to update the example to have this logic already? Could be useful.
This is the modified code at the beginning of the defineConfig
function:
// Ensure the certificate and key exist
if (process.env.ASPNETCORE_ENVIRONMENT === 'Development' && (!fs.existsSync(certFilePath) || !fs.existsSync(keyFilePath))) {
// Make the cert folder if missing
if (!fs.existsSync(baseFolder))
fs.mkdirSync(baseFolder);
Not sure if there is a downside, but I changed the cert path to:
const baseFolder =
`${process.env.PWD}/.certs`;
This helps get around permission issues when making the directory if it doesn't exist (something that has to be manually fixed when running the original example on OSX)
Describe the bug When running Azure Pipelines and building in Release mode, I get the following error:
There was an error exporting the HTTPS developer certificate to a file. Please create the target directory before exporting. Choose permissions carefully when creating it.
To Reproduce Set up a build pipeline with a project using Vite.AspNetCore. In this case I used the example MVC project.
Expected behavior For the built to complete. Since I am targeting
Release
, it shouldn't even be asking for a HTTPS developer certificate.Screenshots
Device (please complete the following information):
Additional context This is my build task in Cake: