2016-06-17 3 views
0

zeigt Ich verwende Meteor als Back-End für meine ionic+angular WebApp. Ich stelle die App unter Verwendung von meteor-up bereit. Ich habe meine ganze app im Meteor/public Ordner abgelegt und es funktioniert finden, wenn ich es so Zugang:Wie kann ich die Standardseite in Meteor so umschreiben/umleiten, dass sie auf /public/index.html

http://localhost:3000/index.html

Wie kann ich/Rewrite/redirect die Meteor Standardseite, so kann ich die gleiche Seite laden von:

http://localhost:3000/ oder http://localhost:3000/myApp

ohne mein Meteor Server zu verlieren

Antwort

0

Hier ist die vollständige Lösung:

fs = Npm.require('fs'); 
crypto = Npm.require('crypto'); 
WebApp.connectHandlers.use("/", function(req, res, next) { 
    var data, filepath; 
    if (req.method !== 'GET') { 
    return next(); 
    } 
    filepath = process.env.PWD + '/public/index.html'; 

    // serve default file, with eTag, 
    // i.e. http://localhost:3000/ 
    fs.readFile(filepath, function(err, buf) { 
    var eTag; 
    eTag = crypto.createHash('md5').update(buf).digest('hex'); 
    if (req.headers['if-none-match'] === eTag) { 
     res.writeHead(304, 'Not Modified'); 
     return res.end(); 
    } 
    res.writeHead(200, { 
     'ETag': eTag, 
     'Content-Type': 'text/html' 
    }); 
    return res.end(buf); 
    }); 
    return; 

    // serve default file, without eTag or caching headers 
    // i.e. http://localhost:3000/ 
    data = fs.readFileSync(filepath); 
    res.writeHead(200, { 
    'Content-Type': 'text/html' 
    }); 
    res.write(data); 
    return res.end(); 

    // redirect to default file 
    // i.e. http://localhost:3000/index.html 
    res.writeHead(301, { 
    'Location': '/index.html' 
    }); 
    return res.end(); 
}); 
Verwandte Themen