Run ionic web app in nodejs

石橋碼農發表於2015-07-09
首先需要express外掛:sudo npm install express

將ionic project的www拷貝至wwwroot,新建server.js:

var express = require('express'),
    // employees = require('./routes/employees'),
    app = express();
 
app.use(express.static('www'));
 
// CORS (Cross-Origin Resource Sharing) headers to support Cross-site HTTP requests
app.all('*', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    next();
});
 
app.get('/', function (request, response) {
    response.sendFile(__dirname + "/www/index.html");
});
 
app.set('port', process.env.PORT || 5000);
 
app.listen(app.get('port'), function () {
    console.log('Express server listening on port ' + app.get('port'));
});

then: node server 

 

相關文章