Saturday 13 May 2017

Use `index.html` rather than `index.ejs`

I have a mean-stack application. By going to https://localhost:3000/#/home, it reads views/index.ejs. Here is the setting in app.js:

var app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.all('/*', function(req, res, next) {
    res.sendFile('index.ejs', { root: __dirname });
});

Actually, I don't use the feature of ejs in index.ejs. So now I want to use just a index.html rather than index.ejs.

I put the content of index.ejs in public/htmls/index.html and views/index.html. And here is the current setting in app.js:

var app = express();
// app.set('views', path.join(__dirname, 'views'));
// app.set('view engine', 'ejs');
app.all('/*', function(req, res, next) {
    res.sendFile('index.html', { root: __dirname });
    // res.sendFile('index.html'); // does not work either
});

However, running https://localhost:3000/#/home returns

Error: No default engine was specified and no extension was provided.

Does anyone know how to fix it?



via SoftTimur

No comments:

Post a Comment