nunjucks从swig迁移

时间:2018-02-26 20:21:48

标签: node.js express nunjucks

我已经使用swig作为模板引擎构建了一个应用程序;但是,由于最近的升级,我不得不迁移到nunjucks。我有一个页面正在渲染,但没有附加样式或JavaScript。代码适用于swig,但它似乎并没有引入样式表或JavaScript文件的内容。

   // setup db
mongoose.connect(secrets.db);
mongoose.connection.on('error', function() {
console.error('MongoDB Connection Error. Make sure MongoDB is running.');
});

var corsOptions = {
origin: '*'
};

// express setup
var app = express();



// This is where all the magic happens!

nunjucks.configure(path.join(__dirname, 'views'), {
autoescape: true,
express: app,
noCache : app.get('env') === 'development',
watch: true
});
app.get('/', function(req, res) {
res.render('index.html');
});
app.locals._ = lodash;
app.locals.stripePubKey = secrets.stripeOptions.stripePubKey;


app.use(favicon(path.join(__dirname + '/../public/favicon.ico')));
app.use(logger('dev'));

app.use(compress);
app.use(bodyParser());
app.use(expressValidator());
app.use(cookieParser());

app.use(express.static(__dirname));
if(app.get('env') !== 'production'){
app.use('/styles', express.static(__dirname + '/../.tmp/styles'));
// app.use('/', routes.styleguide);
}

app.use(session({
resave: true,
saveUninitialized: true,
cookie: {
maxAge: 60 * 1000 // 1 minute
},
secret: secrets.sessionSecret,
store: new MongoStore({
url: secrets.db,
auto_reconnect: true
})
}));

// setup passport authentication
app.use(passport.initialize());
app.use(passport.session());

// other
app.use(flash());
app.use(cors(corsOptions));

var passportMiddleware = require('./middleware/passport');
passportMiddleware(passport);

// setup view helper
app.use(viewHelper);

// setup routes
var routes = require('./routes');
routes(app, passport);

/// catch 404 and forwarding to error handler
app.use(errorHandler.notFound);

/// error handlers
if (app.get('env') === 'development') {
app.use(errorHandler.development);
} else {
app.use(errorHandler.production);
}

module.exports = app;

它不会丢失任何错误,只是没有内容被用于样式或JavaScript。

0 个答案:

没有答案