Mamy tu jakiś speców expressa :)?
Mam loadera którego zadaniem jest wrzucenie odpowiedniej konfiguracji do midleware.
const EnviromentLoader = require('./loaders/EnviromentLoader');
EnviromentLoader.setEnviroment(app);
Który na podstawie tego ładuje odpowiednią mapę.
const devConfig = require('../config/dev.js');
const prodConfig = require('../config/prod.js');
const EnviromentLoader = {
enviroments: {
'dev': devConfig,
'prod': prodConfig
},
loadConfig: function(env) {
return this.enviroments[env];
},
setEnviroment: function(app) {
app.set('config', this.loadConfig(process.argv[2]));
}
}
Mam routeControler która zwraca funkcje (obiekt) zadaniem Kontrolera jest sprawdzenie czy user ma dostęp do wskazanych zasobów.
module.exports = function(req, res, next) {
// If the request wasn't a POST request, pass along to the next handler immediately.
if (req.method !== 'POST') return next();
// Perform your validations.
Check(req.body, function(err) {
// Validation failed, or an error occurred during the external request.
if (err) return res.sendStatus(400);
// Validation passed.
return next();
});
};
Zamysł miałem taki, że routerControler będzie sprawdzał config jeśli się znajduje w tablicy to... jeśli nie to strona główna jeśli w ogóle to jest błąd to 404. Owszem mogę po przez require dokleić mu config, ale może istnieje jakiś na to sposób?