Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I'm working on the seed project now

I want to use

nodejs as api server listening on port 5001,

express as back-end framework,

angularjs as front-end framework,

and apache as static file server (such as lots of .js file that angular requires) listening on port 5000


In angular, I have configuration below

app.config(['$locationProvider', function ($locationProvider) {
    $locationProvider.html5Mode(true);
    $locationProvider.hashPrefix('!');
}]);

As for apache, I add the following configuration to /etc/apache2/sites-available/000-default.conf

Listen 5000

<VirtualHost *:5000>
    DocumentRoot /var/www/seed/public
    <Directory /var/www/seed/public >
        AllowOverride All
    </Directory>
</VirtualHost>

I also add /public/.htaccess file

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # support angular
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*) /#!/$1 
</IfModule>

The current rewrite rule is for angular, because it needs a hashbang when a user refresh the page


Now I don't know how to redirect api request with URL starting with /api to port 5001

Is it possible to do this with .htaccess file?

And is there any better way to cooperate with nodejs, angularjs and apache?

I couldn't find any tutorial about this kind of combination...

Thanks for reading or answering my question

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.