k Kqwer
k Kqwer

Reputation: 53

REST api doesn't seem to work in grails with vue profile

I was following this guide about creating a grails+vue web and created the following "Person" class:

package kpm2

import grails.rest.*

@Resource(uri = '/person', formats = ["json", "xml"])
class Person {

    String name
    int age

    static constraints = {
        name blank: false
    }
}

@Resource should make it possible to perform REST operations, such as (as shown in the guide):

$ curl -X "GET" "http://localhost:8080/vehicle"

HTTP/1.1 200
X-Application-Context: application:development
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Fri, 06 Jan 2017 19:28:49 GMT
Connection: close

[{"id":1,"driver":{"id":1},"make":{"id":1},"model":{"id":1},"name":"Pickup"},
{"id":2,"driver":{"id":1},"make":{"id":1},"model":{"id":2},"name":"Economy"},
{"id":3,"driver":{"id":2},"make":{"id":2},"model":{"id":3},"name":"Minivan"}]

(in the guide they make a vehicle garage with other interconnected classes, but for simplicity and testing purposes I just created a simple Person class. I also followed the guide completely before, but it also didnt work)

But it doesnt work for me. I get this :

$ curl -X "GET" "http://localhost:8080/#/person"

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  <link rel="icon" href="/favicon.ico">
  <title>Welcome to Grails & Vue</title>
<link href="/js/app.js" rel="preload" as="script"><link href="/js/chunk-vendors.js" rel="preload" as="script"></head>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script type="text/javascript" src="/js/chunk-vendors.js"></script><script type="text/javascript" src="/js/app.js"></script></body>
</html>

http://localhost:8080/#/person doesnt seem to exist, even though i specified it in @Resource(uri = "/person")

I dont know what the problem is. I even did some integration tests to see if a Person can be added to the database and they check out. Following further the guide, the "persons" I added to the database in BootStrap.groovy are not shown in the table that should contain them.


Also the official guide for REST in grails doesn't work in the same way.


I created a new grails app with grails create-app -profile=vue with grails version 5.18

Upvotes: 0

Views: 81

Answers (1)

k Kqwer
k Kqwer

Reputation: 53

I found that the problem was because of the ports in the docker container configuration.

It worked with this container build:

docker run -p 8080:8080 -p 8081:3000 -v $(pwd):/app <image>

Upvotes: 0

Related Questions