Use pomelo.js instead of sails.js - EJS view renderer

Vadorequest Source

I'm using sails.js, but I'm trying to change and use pomelo.js instead.

Both are based on express.js.

But I encountered some troubles, here my web-server/app.js

var express = require('express'); var app = express(); var port = 1337; // Supposed help and read .html file with EJS renderer app.engine('.html', require('ejs').__express);

app.configure(function(){ app.use(express.methodOverride());
app.use(express.bodyParser()); app.use(app.router); app.set('view engine', 'ejs'); app.set('views', _dirname + '/public/views');
app.set('view options', {layout: 'layout'}); // Name of the layout? Found nothing about view options... app.set('basepath',
_dirname + '/public'); });

app.configure('development', function(){
app.use(express.static(__dirname + '/public/views/main')); app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); });

app.configure('production', function(){ var oneYear = 31557600000;
app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
app.use(express.errorHandler()); });

console.log("Web server has started.\nPlease log on http://localhost.com:"+port+"/index.html");

app.listen(port);

But when I go in the page, the EJS code is not interpreted but displayed. My file in views/main is called index.html. I tried to call it index.ejs but if I do that I have the message: Cannot GET /

So I don't know what to do, I tried a lot of things, I read the express.js doc and search examples but nothing works. I'm using

"lodash": "~2.2.1",
"ejs": "~0.8.4",
"express": "~3.4.0"

Thank you for your help. PS: Please add the tag pomelo.js, I can't. http://pomelo.netease.com/

node.jsexpressviewssails.jsejs

Answers

answered 5 years ago Vadorequest #1

Finally:

var express = require('express');
var app = express();
var port = 1337;

var format = require('../game-server/app/util/format');

app.configure(function(){
    app.use(express.methodOverride());
    app.use(express.bodyParser());
    app.use(app.router);
    app.set('view engine', 'ejs');
    app.set('views', __dirname + '/views');
    var oneYear = 31557600000;
    var oneDay = 86400000
    app.use(express.static(__dirname + '/public', { maxAge: oneDay }));
    app.use(function(req, res, next){
        res.status(404).render('404');
    });
});

app.configure('development', function(){
    app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('production', function(){
    app.use(express.errorHandler());
});

var getRoutePage = {
    welcome : {
        title : "Welcome",
        mainRender : "main/index.ejs",
        layout : "main/layout.ejs"
    }
};

/**
 * Default index page
 */
app.get('/', function(req, res){
    res.render(getRoutePage.welcome.mainRender, function(err, html){

        var data = {
            title: getRoutePage.welcome.title,
            body: html,
            langScript : '<script src="lang/fr.js"></script>',
            langTag : "fr"
        };

        // Second rendu.
        res.render(getRoutePage.welcome.layout, data);
    });
});

console.log("Web server has started.\nPlease log on http://127.0.0.1:"+port+"/index.html");

app.listen(port);

comments powered by Disqus