I’m new to this and I’m trying to connect my frontend and backend so that it can receive and send data. But I can’t seem to get it to work.
This is the code for launchsettings.json on backend:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:56440",
"sslPort": 44385
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"WebAPIv1._1": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}
While this is the code for proxy.js in frontend:
const { createProxyMiddleware } = require("http-proxy-middleware");
import * as Path from "../Productivity/state/apiRoutes";
module.exports = app =>{
app.use(
createProxyMiddleware('/department',
{
target : 'https://localhost:44385/api',
changeOrigin : true
})
)
}
What do I need to do to have both frontend and backend to run on ngrok?
I’ve tried the connecting frontend and backend by opening up ngrok.yml and change the code inside to:
version: "2"
authtoken:
tunnels:
frontend:
proto: http
addr: 3000
backend:
proto: http
addr: 44385
and run ngrok start frontend backend
on ngrok.exe
I can open the frontend url from ngrok and get errors when I try to login to the website-application since it cant connect to the backend, and then I get ERR_NGROK_3004 on backend url from ngrok.
Appreciate any help!
2
Answers
I've overall found a solution, sorry I'm new. Nothing wrong with the code above at all, just need to use https properly. Ngrok HTTPS
My ngrok.yml file:
Then just connect the frontend to the backend by changing the URL paths as Jason said, change it to the ngrok url, I also changed the .env URL path.
In my case it was:
Where you host your applciation? Kestrel or IIS? The
launchsettings.json
file is only applicable to Visual Studio or other compilers, if your project is launched through Kestrel, you need to add the following code.In my sample you could find I am using 5031, you need change to 5000.
Suggestion
In your visual studio choose
WebAPIv1._1
, then start.I haven’t tried to use ngrok.yml, so suggest you use command to expose the backend application port. By using
You can change setting like below
The change the targetUrl,like below