зеркало из https://github.com/mozilla/makerparty.git
Remove some variables and fix some nunjucks stuff
This commit is contained in:
Родитель
be400a428b
Коммит
f8b525b5b3
|
@ -19,7 +19,7 @@ module.exports = function (grunt) {
|
|||
options: {
|
||||
async: true
|
||||
},
|
||||
command: 'node server/server.js'
|
||||
command: 'node app.js'
|
||||
}
|
||||
},
|
||||
jshint: {
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
var habitat = require('habitat');
|
||||
var express = require('express');
|
||||
var nunjucks = require('nunjucks');
|
||||
var path = require('path');
|
||||
var i18n = require('webmaker-i18n');
|
||||
var nunjucksEnv = new nunjucks.Environment( new nunjucks.FileSystemLoader(path.join(__dirname, 'views')));
|
||||
|
||||
habitat.load();
|
||||
|
||||
var app = express(),
|
||||
env = new habitat();
|
||||
|
||||
app.use(express.logger('dev'));
|
||||
app.use(express.compress());
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded());
|
||||
|
||||
nunjucksEnv.express(app);
|
||||
nunjucksEnv.addFilter('instantiate', function(input) {
|
||||
var tmpl = new nunjucks.Template(input);
|
||||
return tmpl.render(this.getVariables());
|
||||
});
|
||||
|
||||
var healthcheck = {
|
||||
version: require('./package').version,
|
||||
http: 'okay'
|
||||
};
|
||||
|
||||
// Setup locales with i18n
|
||||
app.use( i18n.middleware({
|
||||
supported_languages: [ 'en-US' ],
|
||||
default_lang: 'en-US',
|
||||
mappings: require('webmaker-locale-mapping'),
|
||||
translation_directory: path.resolve(__dirname, 'locale')
|
||||
}));
|
||||
|
||||
// Static files
|
||||
app.use(express.static(path.resolve(__dirname, 'public')));
|
||||
|
||||
// Healthcheck
|
||||
app.get('/healthcheck', function (req, res) {
|
||||
res.json(healthcheck);
|
||||
});
|
||||
|
||||
app.get('/', function(req, res){
|
||||
res.render('home.html');
|
||||
});
|
||||
|
||||
app.get('/partners', function(req, res){
|
||||
res.render('partners.html');
|
||||
});
|
||||
|
||||
app.get('/resources', function(req, res){
|
||||
res.render('resources.html');
|
||||
});
|
||||
|
||||
app.get('/history', function(req, res){
|
||||
res.render('history.html');
|
||||
});
|
||||
|
||||
// Localized Strings
|
||||
app.get('/strings/:lang?', i18n.stringsRoute('en-US'));
|
||||
|
||||
// Run server
|
||||
app.listen(env.get('PORT'), function () {
|
||||
console.log('Now listening on %d', env.get('PORT'));
|
||||
});
|
|
@ -1,74 +0,0 @@
|
|||
module.exports = function (env) {
|
||||
var express = require('express');
|
||||
var nunjucks = require( "nunjucks" );
|
||||
var path = require('path');
|
||||
var i18n = require( "webmaker-i18n" );
|
||||
console.log(i18n);
|
||||
var app = express();
|
||||
var nunjucksEnv = new nunjucks.Environment( new nunjucks.FileSystemLoader( "./public"));
|
||||
var defaultLang = 'en-US';
|
||||
var appVersion = require('../package').version;
|
||||
|
||||
app.use(express.logger('dev'));
|
||||
app.use(express.compress());
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded());
|
||||
|
||||
nunjucksEnv.express( app );
|
||||
nunjucksEnv.addFilter( "instantiate", function( input ) {
|
||||
var tmpl = new nunjucks.Template( input );
|
||||
return tmpl.render( this.getVariables() );
|
||||
});
|
||||
|
||||
var config = {
|
||||
version: appVersion
|
||||
};
|
||||
|
||||
var healthcheck = {
|
||||
version: appVersion,
|
||||
http: 'okay'
|
||||
};
|
||||
|
||||
// Setup locales with i18n
|
||||
app.use( i18n.middleware({
|
||||
supported_languages: [ "*" ], // TO FIX: config.SUPPORTED_LANGS ???
|
||||
default_lang: "en-US",
|
||||
mappings: require("webmaker-locale-mapping"),
|
||||
translation_directory: path.resolve( __dirname, "../locale" )
|
||||
}));
|
||||
|
||||
// Localized Strings
|
||||
app.get("/strings/:lang?", i18n.stringsRoute("en-US"));
|
||||
|
||||
// Static files
|
||||
app.use(express.static('./public'));
|
||||
|
||||
// Healthcheck
|
||||
app.get('/healthcheck', function (req, res) {
|
||||
res.json(healthcheck);
|
||||
});
|
||||
|
||||
// Serve up virtual configuration "file"
|
||||
app.get('/config.js', function (req, res) {
|
||||
res.setHeader('Content-type', 'text/javascript');
|
||||
res.send('window.eventsConfig = ' + JSON.stringify(config));
|
||||
});
|
||||
|
||||
app.get('/', function(req, res){
|
||||
res.render("views/home.html");
|
||||
});
|
||||
|
||||
app.get('/partners', function(req, res){
|
||||
res.render("views/partners.html");
|
||||
});
|
||||
|
||||
app.get('/resources', function(req, res){
|
||||
res.render("views/resources.html");
|
||||
});
|
||||
|
||||
app.get('/history', function(req, res){
|
||||
res.render("views/history.html");
|
||||
});
|
||||
|
||||
return app;
|
||||
};
|
|
@ -1,14 +0,0 @@
|
|||
var Habitat = require('habitat');
|
||||
|
||||
Habitat.load();
|
||||
|
||||
// Configuration
|
||||
var env = new Habitat();
|
||||
|
||||
// App
|
||||
var app = require('./config')(env);
|
||||
|
||||
// Run server
|
||||
app.listen(env.get('PORT'), function () {
|
||||
console.log('Now listening on %d', env.get('PORT'));
|
||||
});
|
|
@ -145,7 +145,6 @@
|
|||
</div>
|
||||
</footer>
|
||||
|
||||
<script src="config.js"></script>
|
||||
<script src="bower_components/jquery/dist/jquery.min.js"></script>
|
||||
<script src="bower_components/jquery-colorbox/jquery.colorbox-min.js"></script>
|
||||
<script src="bower_components/bootstrap/js/collapse.js"></script>
|
||||
|
|
Загрузка…
Ссылка в новой задаче