1

I am trying to move an application off of PHP and onto Node.js. The PHP application uses an Apache server and has a tileservices.conf file that is necessary for the app to work. How would I move over the configuration in this file to a Node application?

Alias /tiles /sandbox/TileServices/www/TileStreamer.php
Alias /thumbs /sandbox/TileServices/www/ThumbStreamer.php
Alias /MosaicTest /sandbox/TileServices/www/MosaicTest

RewriteEngine on
RewriteRule ^/1.0.0/([a-zA-Z0-9]*)/([0-9]*)/([0-9]*)/([0-9]*)\.[a-zA-Z]*$ /sandbox/TileServices/tiles/tc/cache_server.php?z=$2&c=$3&r=$4&cache=$1
RewriteRule ^/nwomtest/1.0.0/(.+)/(.+)/(.+)/(.+)\.[a-zA-Z]*$ /sandbox/TileServices/www/tc/cache_server_new.php?z=$2&c=$3&r=$4&cache=$1
RewriteRule ^/nocache/nwomtest/1.0.0/(.+)/(.+)/(.+)/(.+)$ /sandbox/TileServices/www/tc/cache_server_new.php?z=$2&c=$3&r=$4&cache=$1&do_not_cache=nocache
RewriteRule ^/nocache/nwomtest/1.0.0/(.+)/(.+)/(.+)/(.+)\.[a-zA-Z]*$ /sandbox/TileServices/www/tc/cache_server_new.php?z=$2&c=$3&r=$4&cache=$1&do_not_cache=nocache

RewriteRule ^/oms/1.0.0/(.+)/(.+)/(.+)/(.+)\.[a-zA-Z]*$ /sandbox/TileServices/www/MosaicRequestHandler.php?z=$2&c=$3&r=$4&library=$1&filestyle=strip
RewriteRule ^/omb/1.0.0/(.+)/(.+)/(.+)/(.+)\.[a-zA-Z]*$ /sandbox/TileServices/www/MosaicRequestHandler.php?z=$2&c=$3&r=$4&library=$1&filestyle=block
RewriteRule ^/ms/1.0.0/(.+)/(.+)/(.+)/(.+)/(.+)\.[a-zA-Z]*$ /sandbox/TileServices/www/Mosaic/Mosaic.php?z=$3&c=$4&r=$5&resource=$1&tkid=$2&filestyle=strip
RewriteRule ^/mb/1.0.0/(.+)/(.+)/(.+)/(.+)/(.+)\.[a-zA-Z]*$ /sandbox/TileServices/www/Mosaic/Mosaic.php?z=$3&c=$4&r=$5&resource=$1&tkid=$2&filestyle=block

<Directory "/sandbox/TileServices/www">
    AllowOverride None
    Options -Indexes
    Require all granted

    <IfModule speling>
        CheckSpelling on
    </IfModule>

    SetEnv MOUNT_PREFIX "/mnt/autofs"
</Directory>

<Directory "/sandbox/TileServices/www/tiles/MosaicTest">
    Require all denied
    Allow from 10.0.0.0/8
    Allow from 172.16.0.0/12
    Allow from 192.168.0.0/16
    Allow from 206.90.52.6/32
</Directory>
Sara Fuerst
  • 5,688
  • 8
  • 43
  • 86

1 Answers1

-1

Edited:

//a ton of info on routing http://expressjs.com/en/guide/routing.html

for the first part (until first 2x new line)

you pretty much need express to do the following:

app.get('/tiles', function (req, res) {
  res.send('GET request to /tiles'); //or some other logic
});
app.get('/thumbs', function (req, res) {
  res.send('GET request to /tiles'); //or some other logic
});
app.get('/MosaicTest', function (req, res) {
  res.send('GET request to /tiles'); //or some other logic
});

Second part:

// ^/1.0.0/([a-zA-Z0-9]*)/([0-9]*)/([0-9]*)/([0-9]*)\.[a-zA-Z]*$

app.get('/1.0.0/:param1/:param2/:param3/:param4', function (req, res) {
  var param1 =req.params.param1,
   param2 = req.params.param2,
   param3 = req.params.param3,
   param4 = req.params.param4;

  res.send('your first route parameter is '+param1); //or some other logic
});

First part will probably not be a problem becase Node.js will NOT serve directories and files unless you program it too. So your server is protected.

Second part if those are files (like images) you probably need to think of way to send those to the user trough node. If those are just pages/other data you will serve trough Node you basically need to filter the IP-s that access them so something along the lines of

//    this goes after your route definition
// so after something like app.get('/MosaicTest', function (req, res) { 
var ip = req.ip; 
if (ip == '127.0.0.1') {
    res.send('ip not allowed');
    res.end();
}
// close route definition });
// source: http://stackoverflow.com/questions/12349251/restrict-access-to-node-js-based-http-server-by-ip-address

might help

Sadly I am no node.js expert myself so you will need to look for other answers or ask more specific questions to get it all done.

Hope it all helps you on your way! :)

Hop hop
  • 841
  • 8
  • 21
  • We don't still need Apache and PHP! One is entirely a PHP app, which is being moved to an entirely Node app. The file I posted is the configuration file that the PHP app uses. I don't know how to move these configuration settings into a Node app. I am currently using express, which handles routing, but not the server configuration – Sara Fuerst Apr 21 '16 at 15:48
  • I extended my answer. You might want to try express. It allows you to do routing similar to .htaccess . – Hop hop Apr 21 '16 at 15:50
  • Well I am using Express for the routing, but I don't know how to use it for server configuration – Sara Fuerst Apr 21 '16 at 15:51
  • It looks to me like the first dozen lines are perfectly doable by Express means. Is it the things that you need help with or all of the statements in the code you posted? – Hop hop Apr 21 '16 at 15:52
  • Pretty much everything! I'm new to Apache and Node -_- – Sara Fuerst Apr 21 '16 at 15:53
  • Thank you so much! – Sara Fuerst Apr 21 '16 at 15:55
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/109835/discussion-between-yavor-kirov-and-tibsar). – Hop hop Apr 21 '16 at 16:10