How to remove app name and port from url in grails? - url

Instead of deploying my app to
http://localhost:8080/myApp
I want to deploy it to
http://localhost

To change the run-app port, edit grails-app/conf/BuildConfig.groovy and add the line
grails.server.port.http = 80
To remove the context (the 'myApp' part) edit application.properties and add the line
app.context=/

deploy your app to a tomcat server with the war name as ROOT.war.
Because war names describe contexts... papa.war will be available through [root_domain]/papa

To remove the port, use:
grails -Dserver.port=80 run-app

Related

Grails 3 - change default port for run-app

In Grails3 grails -Dserver.port=9001 run-app doesn't appear to work:
I'm "getting address already bound 8080".
Any idea how to do this - ideally by passing a property to "gradle run"?
You can use
server:
port: 9001
in application.yml.
Or you can pass it via system environment. (e.g. SERVER_PORT=9001 grails run-app).
grails run-app --port=8081
Or in interactive mode:
run-app --port=8081
Don't forget to use the same port when you want to stop the server:
stop-app --port=8081
I believe this feature was broken in 3.0.3 and earlier versions but it definitely works in 3.0.4.
Accepted answer is correct. For some additional info, Grails 3 uses spring-boot and the server properties are configured by the
org.springframework.boot.autoconfigure.web.ServerProperties
class. "port" is just a property on this class which is filled from the application.yml with the prefix "server". So in addition to the port, you can set properties of this class including tomcat configuration properties and etc. To change the contextPath for instance you add
server:
contextPath: /myapp
to you application.yml.
server:
port: 9809
contextPath: '/admin/'
you can use this in your application.yml file
or change the port depends on the environment for example :
environments:
test:
grails:
serverURL: "http://localhost:9809"

Deploy grails as Tomcat Root

I have been deploying my webapp with <app-name>.war in my case tao.war.
Now I need to deploy it in the tomcat ROOT.
So I was renaming tao.war in ROOT.war. Everything seemed to work but when I was editing a domain class respective update was done in the DB but I got forwarded to
localhost:8080/tao/person/show/1
where I was expecting
localhost:8080/person/show/1
without the app-name.
Where does the app-name in the URL come from? Where am I missing something.
Try this:
grails.app.context = '/'
in Config.groovy.
Enjoy.

Grails external configuraiton issue

Externalizing Grails Datasource configuration
i have followed the steps in answered section of above question.
grails.config.locations = [ "classpath:appconfig.properties"]
and placed appconfig.properties in conf folder. But this configuration is loading. what is the most trusted way to load external database configruation in grails ? My grails version is 1.3.7.
EDIT:
Just now i have changed this code to
grails.config.locations = ["file:${userHome}/.grails/appconfig.groovy"]
and placed the config file in .grails folder in my home folder. it is working in GGTS and war file also.
Your config is not loaded when running with grails run-app? Or in deployment on tomcat? Or either?
Try to look at this answer

grails.server.port has no effect anymore in BuildConfig.groovy

grails.server.port has no effect anymore in BuildConfig.groovy
should always pass
-Dserver.port=XXXX
Grails version 2.1.1
It is
grails.server.port.http = xxxx
not
grails.server.port = xxxx
But there are something further to be checked:
If you deploy the app upon Unix platforms, all ports below 1024 can only be accessed by root user. Otherwise you will get an error like Error Server failed to start for port 80: Permission denied
The redirect() method uses the grails.serverURL config setting to generate the redirect URL. You may need to remove the setting, particularly from the development and test environments.

How to change grails localhost port?

I'm using grails 2.0.4. And I want to use port:8090 instead of 8080 for localhost. So need help to change the port to 8090 permanently.
This solution adds to the answers http://stackoverflow.com/a/10956283/122457. In Grails 2.x,
add the following to BuildConfig.groovy:
grails.server.port.http = 8090
See http://forum.springsource.org/archive/index.php/t-97024.html for further details.
There are two options:
Change grails.serverURL in Config.groovy from "http://localhost:8080/${appName}" to "http://localhost:8090/${appName}".
Launch grails with -Dgrails.server.port.http=8090 on the command line. Set the GRAILS_OPTS environment variable to -Dgrails.server.port.http=8090 to have it applied automatically.
If you are using Netbeans IDE then set the following -:
Config: -> BuildConfig.groovy: -> grails.server.port.http = 8090
and restart the server.
Without IDE, type in the command prompt -:
grails -Dserver.port 8090 run-app
or
grails -Dserver.port=8090 run-app
For grails 3 you can put this in your application.yml
server:
port: 9999
command line: grails run-app -port 8090
Run the command (Ctrl+Alt+g)
Up to grails version 2.x : run-app -Dserver.port=8090
For grails version 3.x : run-app --port=8090
If you are using IntelliJ IDE then
From the application menu click Run >> Edit Configurations... >> VM options: -Dgrails.server.port.http=8180
grails run-app -Dserver.port=8090
Or use another port number
In Intellij:
Ctrl+Alt+G (keyboard Generic);
Cmd+Alt+G (keyboard Mac)
and use only:
run-app -Dserver.port=8090
Add/Update the value of port from your application.yml (grails-app/conf/application.yml)
environments:
development:
server:
port: "8090"
Or
server:
port: "8090"
Type following in the command line:
grails -Dserver.port=8090 run-app
You didn't say what IDE you are using. If you are using Netbeans you just right-click on the project name and choose Properties. From the General Settings Category, you can easily change the server port to whatever you like.
You can run grails app using the following command on the terminal. default running port is 8080.
grails run-app -Dserver.port=9090
This will run the app on port 9090.
For Grails 4 required two settings
server:
port: "8085"
grails:
serverURL: http://localhost:8085
Second one will solve redirection issues
Or only for dev:
environments:
development:
server:
port: "8085"
grails:
serverURL: http://localhost:8085

Resources