-1

I'm currently building a Hal Hateoas RESTful API with BazingaHateoasBundle and Symfony 2.7

Here is my config file :

MyBundle\Entity\MyEntity:
  relations:
    - rel: self
      href:
        route: get_myentity
        parameters:
          id: expr(object.getId())
        absolute: true

In local, I have an apache with a virtual host and my responses are correct :

{
    "id":1,
    "_links": {
        "self": {
            "href": "http://dev.myvhost/api/myentity/1"
        }
}

In my dev server, I have something like this:

{
    "id":1,
    "_links": {
        "self": {
            "href": "http://my-machine-name/api/myentity/1"
        }
}

I don't want my-machine-name but my-server-name.com instead.

And my server Apache config look like this :

ServerName my-server-name.com
Alias "/api" "/var/www/api/web"

<VirtualHost *:80>
    <Directory /var/www/api/web>
        AllowOverride None
        Require all granted
        Allow from All

        <IfModule mod_rewrite.c>
           Options -MultiViews
           RewriteEngine On
           RewriteCond %{REQUEST_FILENAME} !-f
           RewriteRule ^(.*)$ /api/app.php [QSA,L]
        </IfModule>
    </Directory>

    <Directory /var/www/api/web/bundles>
        <IfModule mod_rewrite.c>
            RewriteEngine Off
        </IfModule>
    </Directory>
    ErrorLog /var/log/httpd/api_error.log
    CustomLog /var/log/httpd/api_access.log combined
</VirtualHost>

Is there a way to configure Symfony so that I can set directly the host maybe ?

bguyl
  • 383
  • 3
  • 10

1 Answers1

-2

I think you're missing a step here. That is you need to add the my-server-name.com to the hosts file (of the system).

Here's another helpful link on the topic: Symfony 2 on virtual hosts