1

I am creating a small Angular 2 application with a php based REST API. The way I have been developing it so far is I created mock data in a json file and used that to create the front end. I created the php REST API using MAMP and tested it separately and it works fine. The problem I am having is I would like to test the integration of both of them but when I run the npm lite server and try to make an HTTP request to the API it doesn't work. Is there a npm server I can use instead of the lite-server that would run the php API? Or is there another solution I am completely overlooking?

2 Answers 2

1

I actually found one solution. So I can enable CORS on my local MAMP server by editing the Apache configuration file. In case anybody needs to do something similar here is a very short tutorial on how to do the same:

http://enable-cors.org/server_apache.html

This works great for my needs.

Sign up to request clarification or add additional context in comments.

Comments

0

You can also just do it in your PHP file so you don't have to fiddle with apache:

<?php
header('Access-Control-Allow-Origin: *');
header('ContentType: application/json');
echo json_encode('whatever');
exit;
?>

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.