This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RoutingDataSourceImpl extends AbstractRoutingDataSource { | |
@Override | |
protected Object determineCurrentLookupKey() { | |
return "ds1"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// normal way | |
app.get("/myroute", function(request, response, next){ | |
response.render("myroute", {}); | |
}); | |
// dynamic way | |
// method = GET | |
// path = "/" | |
// route[method][path] = function(request, response, next){ | |
// response.render("myroute", {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// route load and initialization | |
fs.readdirSync("routes").forEach(function(file){ | |
var route = require("./routes/"+file); | |
for(var method in route){ | |
for(var path in route[method]){ | |
app[method](path,route[method][path]); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.get = {}; | |
exports.post = {}; | |
exports.all = {}; | |
exports.get["/myroute"] = function (request, response, next){ | |
// rendering my template | |
response.render("myroute", {}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// route load and initialization | |
fs.readdirSync("routes").forEach(function(file){ | |
var route = require("./routes/"+file); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs.readdirSync("directory/path").forEach(function(file){ | |
// file treatment | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// post management after get | |
exports.get("/my/admin/url", | |
function(request, response, next){ | |
if(request.session.user){ | |
next(); | |
}else{ | |
response.status(403).redirect("/login"); | |
} | |
}, | |
function(request, response){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 2 options | |
// first, any amount of functions | |
app.get('/myroute1', | |
function(request,response,next){ | |
console.log("first"); | |
next(); | |
}, | |
function(request, response){ | |
console.log("second"); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
<form action="/post?id=2"> | |
<input tpye="text" name="title" /> | |
<input type="submit" value="send" /> | |
</form> | |
*/ | |
export.queryStringTest = function(request, response){ | |
console.log(request.query.id,request.body.title); | |
response.render("index", {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1 2 2.1 2.2 2.3 2.4 | |
app.param("id", function(request, response, next, id){ | |
// we check our id value using a function | |
if(myCheckerFunction(id)){ | |
// we call next to continuing with execution to /post/:id route | |
next(); | |
}else{ | |
next(new Error('Incorrect id')); | |
} | |
}); |