Ich habe ein Problem damit, den Wert von tagid
aus meiner URL zu erhalten: localhost:8888/p?tagid=1234
.
Helfen Sie mir, meinen Controller-Code zu korrigieren. Ich kann den Wert von tagid
nicht abrufen.
Mein Code sieht wie folgt aus:
app.js
:
var express = require('express'),
http = require('http'),
path = require('path');
var app = express();
var controller = require('./controller')({
app: app
});
// alle Umgebungen
app.configure(function() {
app.set('port', process.env.PORT || 8888);
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
app.set('view engine', 'jade');
app.set('views', __dirname + '/views');
app.use(app.router);
app.get('/', function(req, res) {
res.render('index');
});
});
http.createServer(app).listen(app.get('port'), function() {
console.log('Express-Server hört auf port ' + app.get('port'));
});
Controller/index.js
:
function controller(params) {
var app = params.app;
//var query_string = request.query.query_string;
app.get('/p?tagId=/', function(request, response) {
// userId is a parameter in the url request
response.writeHead(200); // return 200 HTTP OK status
response.end('Sie suchen nach tagId' + request.route.query.tagId);
});
}
module.exports = controller;
routes/index.js
:
require('./controllers');
/*
* GET home page.
*/
exports.index = function(req, res) {
res.render('index', {
title: 'Express'
});
};