Wednesday 7 June 2017

Rendering all Angular partials with Express

I'm building a website with MEAN and now I am trying to check if my website is good enough for the Google crawlers but when I use a program to check this it only states that I have one HTML file, which is my JADE file. All my other files are routed with Angular but are not rendered with Express. How can I get this to work?

This is my file structure:

\bin
\node_modules
\public
   \partials
      \all angular partials that I need rendered
\routes
   \index.js
   \users.js
\views
   \layout.jade
   \index.jade
app.js
package.json

This is what I have in my app.js right now:

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var path= require("path");
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var lessMiddleware = require('less-middleware');

 var index = require('./routes/index');
 var users = require('./routes/users');

 var app = express();

 // view engine setup
 app.set('views', path.join(__dirname, 'views'));
 app.set('view engine', 'jade');

 // uncomment after placing your favicon in /public
 //app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
 app.use(logger('dev'));
 app.use(bodyParser.json());
 app.use(bodyParser.urlencoded({ extended: false }));
 app.use(cookieParser());
 app.use(lessMiddleware(path.join(__dirname, 'public')));
 app.use(express.static(path.join(__dirname, 'public')));

And my index.js:

router.get('/', function(req, res) {
   res.render('index');
});



via Larsmanson

No comments:

Post a Comment