0

I want to try and use Swagger on a local development env running on MAMP, but i'm running into issues with the base url of my dev site. The UI is generated fine when i hit http://127.0.0.1:8888/magento_222/swagger but when i use the "try it out" function, the Request URL that is passed in is:

http://127.0.0.1/magento_222/rest/all/V1/calculator/add/1/1

and not

http://127.0.0.1:8888/magento_222/rest/all/V1/calculator/add/1/1

This is kicking the Response Headers:

"error": "no response from server"

which is to be expected since it's not the correct url.

Is there a way to set the base url for swagger so that it takes in the full url and not the partial that is getting passed in now? When i look at the http://127.0.0.1:8888/magento_222/rest/default/schema?services=all path for the full config file that is passed in, it's clear where the issue is:

{
"swagger":"2.0",
    "info":{
        "version":"2.2",
        "title":"Magento Community"
    },
    "host":"127.0.0.1",
    "basePath":"/magento_222/rest/default"

I need to update the host. How is that possible?

1

1 Answer 1

0

Figure out a solution. MAMP is able to run any custom url that you pass in, as long as you set up the configuration files correctly.

In the MAMP dir root set up a directory for the magento install:

/Applications/MAMP/htdocs/magento222.local

In your httpd.conf file you need to enable the use of the correct vhost file and make sure that you are listening on port 80:

file: /Applications/MAMP/conf/apache/httpd.conf

# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80

# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf

In your vhost file you need to set the configurations for the new url path:

file: /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "/Applications/MAMP/htdocs/magento222.local"
    UseCanonicalName Off
    ServerName magento222.local
    ErrorLog "logs/dummy-host2.example.com-error_log"
    CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>

For me, as I'm on OSX, I have to edit my hosts file on my local machine to set up the correct port forwarding. This is a read only file, so you will need to have sudo rights to edit it.

file: /etc/hosts

# mamp custom urls
127.0.0.1 tester.test
127.0.0.1 magento222.test
127.0.0.1 magento220ee.test

From there you just have to make sure that MAMP is using the default port of 80:

enter image description here

You can use the button Set MAMP ports to default to get these settings reset. Now, if you are using port 80 for something else, this might conflict. In that case there might be some more info to reference there. But you should now be able to hit the url and use it to test your APIs without errors

http://magento222.local/

--Edit--

I was originally using the url http://magento_222.test/ which was causing issues with the cookie domain being set. Not sure why, but the underbar in the name didn't jive well with magento and hitting the admin. So removing it did the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.