Hapi.js视图看不到本地脚本 [英] Hapi.js views not seeing local scripts

查看:50
本文介绍了Hapi.js视图看不到本地脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用使用Hapi的服务器来开发应用程序,每当尝试加载.jade文件时都会遇到问题.这是我的index.js文件的当前代码:

I'm currently working on an app with a server that uses Hapi, and I am running into a problem whenever I try to load a .jade file. Here is the current code for my index.js file:

var Hapi = require('hapi');

var internals = {};

internals.main = function() {
  var options = {
    views: {
      engines: { jade: 'jade' },
      path: '../app',
      compileOptions: {
        pretty: true
      }
    }
  };

  this._server = new Hapi.createServer('localhost', 8000, options);

  this._server.route({
    method: 'GET',
    path: '/',
    handler: function(request, reply) {
      reply.view('index')
    }
  });
  // Start server.
  this._server.start()
};

internals.main();

该文件在app目录中具有一系列本地脚本和CSS文件,但是在加载页面index.jade时,它看不到那些本地文件.我是否需要在选项中添加/修改某些内容,或者本地脚本和样式文件的此位置是否是使用Hapi进行玉石编译的问题?

The file has a series of local scripts and CSS files that are in the app directory, but when the page index.jade is loaded, it does not see those local files. Is there something I need to add/modify in my options, or is this location of local scripts and style files a problem with jade compilation using Hapi?

推荐答案

在尝试使用angular.js和hapi.js设置单页应用程序时,我正在寻找类似的解决方案

I was looking for a similar solution, while trying to setup a single page application with angular.js and hapi.js

我发现将以下配置添加到您的服务器路由中将有助于使应用程序可见"/public"目录中的CSS,JS,...文件.

I have found that adding the configuration below to your server routes will help to make CSS, JS, ... files in '/public' directory visible to the application.

server.route({
    method: "GET",
    path: "/public/{path*}",
    handler: {
        directory: {
            path: "./public",
            listing: false,
            index: false
        }
    }
});

希望有帮助.

这篇关于Hapi.js视图看不到本地脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆