<commit_before>var mainApp = module.exports = App.subApp()

var navmenuApp = require("../../msa-navmenu/server")
var userApp = require("../../msa-user/server")

// template
var fs = require('fs');
var mustache = require('mustache');
var template = fs.readFileSync(__dirname+'/views/index.html', "utf8");
mustache.parse(template);

/*mainApp.get("*", function(req, res, next) {
	next();
});*/

// default route
mainApp.setDefaultRoute = function(next) {
	userApp.isFirstRegisterDone(function(err, done) {
		if(err) return next(err)
		if(done) mainApp.defaultRoute = "/page/home"
		else {
			mainApp.defaultRoute = "/user/firstregister"
			userApp.onFirstRegister = function(next) {
				mainApp.setDefaultRoute(next)
			}
		}
		next && next()
	})
}

mainApp.get("/", function(req, res, next) {
	res.redirect(mainApp.defaultRoute)
});

// import some middlewares
App.use(require("body-parser").json());

// partialApp
var partialApp = App.subApp();
mainApp.use("/partial", partialApp);

// subApp routing
/*for(var routeName in App.routes) {
	var subApp = App.getSubAppFromRouteName(routeName);
	if(subApp) {
		mainApp.use("/"+routeName, subApp);
		partialApp.use("/"+routeName, subApp);
	}
}*/
mainApp.use(App.subAppsRouter)
partialApp.use(App.subAppsRouter)

// render view with partial content
mainApp.get('*', function(req, res, next) {
	// check if a sub app have replied a partial
	if(!res.partial) return next();
	var contentPartial = res.partial
	delete res.partial
	// get partial from navmenu
	navmenuApp.getAsPartial(req, res, function(){
		if(!res.partial) return next();
		var headerPartial = res.partial
		delete res.partial
		// get partial form user
		userApp.getAsPartial(req, res, function(){
			if(!res.partial) return next();
			var userPartial = res.partial
			delete res.partial
			// send content
			res.setHeader('content-type', 'text/html')
			var html = mustache.render(template, { headerPartial:headerPartial, userPartial:userPartial, contentPartial:contentPartial })
			res.send(html)
		})
	})
})

// render partial as ajax
partialApp.get("*", function(req, res, next) {
	if(!res.partial) return next();
	res.json(res.partial)
})

// static routing
mainApp.use(App.express.static(App.dirname));<commit_msg>fix getAsPartial conflict<commit_after>var mainApp = module.exports = App.subApp()

var navmenuApp = require("../../msa-navmenu/server")
var userApp = require("../../msa-user/server")

// template
var fs = require('fs');
var mustache = require('mustache');
var template = fs.readFileSync(__dirname+'/views/index.html', "utf8");
mustache.parse(template);

/*mainApp.get("*", function(req, res, next) {
	next();
});*/

// default route
mainApp.setDefaultRoute = function(next) {
	userApp.isFirstRegisterDone(function(err, done) {
		if(err) return next(err)
		if(done) mainApp.defaultRoute = "/page/home"
		else {
			mainApp.defaultRoute = "/user/firstregister"
			userApp.onFirstRegister = function(next) {
				mainApp.setDefaultRoute(next)
			}
		}
		next && next()
	})
}
mainApp.setDefaultRoute()

mainApp.get("/", function(req, res, next) {
	res.redirect(mainApp.defaultRoute)
});

// import some middlewares
App.use(require("body-parser").json());

// partialApp
var partialApp = App.subApp();
mainApp.use("/partial", partialApp);

// subApp routing
/*for(var routeName in App.routes) {
	var subApp = App.getSubAppFromRouteName(routeName);
	if(subApp) {
		mainApp.use("/"+routeName, subApp);
		partialApp.use("/"+routeName, subApp);
	}
}*/
mainApp.use(App.subAppsRouter)
partialApp.use(App.subAppsRouter)

// render view with partial content
mainApp.get('*', function(req, res, next) {
	// check if a sub app have replied a partial
	if(!res.partial) return next();
	var contentPartial = res.partial
	delete res.partial
	// get partial from navmenu
	navmenuApp.getPartial(req, res, function(){
		if(!res.partial) return next();
		var headerPartial = res.partial
		delete res.partial
		// get partial form user
		userApp.getPartial(req, res, function(){
			if(!res.partial) return next();
			var userPartial = res.partial
			delete res.partial
			// send content
			res.setHeader('content-type', 'text/html')
			var html = mustache.render(template, { headerPartial:headerPartial, userPartial:userPartial, contentPartial:contentPartial })
			res.send(html)
		})
	})
})

// render partial as ajax
partialApp.get("*", function(req, res, next) {
	if(!res.partial) return next();
	res.json(res.partial)
})

// static routing
mainApp.use(App.express.static(App.dirname));
{'fraction_non_alphanumeric': 0.16214412811387902, 'fraction_numerical': 0.00044483985765124553, 'mean_word_length': 4.490842490842491, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4284686', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1488, 'n_words': 322}