集成express.js应用程序和docpad [英] Integrate express.js application and docpad

查看:81
本文介绍了集成express.js应用程序和docpad的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用docpad预先生成一个前端html/js应用程序(使用docpad generate --env static).经过几次挂断和balupton的错误修复后,它现在可以很好地工作,并为我节省了很多时间.我只是将这些文件复制到现有的apache服务器中进行部署.

I've been using docpad to pre-generate a front-end html/js application (using docpad generate --env static). After a few hangups and a bug fix from balupton it now works great and saves me a lot of time. I simply copy these file to an existing apache server for deployment.

我现在还创建了一个node.js/express.js后端应用程序,该应用程序使用简单的api将数据提供给客户端.该代码的创建和运行独立于如上所述的docpad/静态文件.

I have now also created a node.js/express.js back-end application that uses a simple api to feed data to the client. This code was created and run independently from the docpad/static files generated as I discussed above.

我现在想将这两者整合在一起.在docpad世界中,这通常是如何完成的?我看到几个选项:

I'd now like to integrate these two. How is this typically done in the docpad world? I see several options:

1)后端代码和前端代码保持分开. Docpad用于生成前端静态文件,然后使用单独的后端应用程序来提供静态文件和数据.仅将静态文件和Express应用程序复制到服务器以进行部署.

1) The back-end and front-end code are kept separate. Docpad is used to generate the front-end static files then a separate back-end application is used to serve the static files and data. Only the static files and express app are copied to the server for deployment.

2)后端源文件与前端文件一起生成,并复制到服务器以进行部署.我猜这与#1几乎相同,只是src/files目录需要包含express.js应用程序文件,并允许我在后端源上运行预处理器.

2) The back-end source files are generated along with the front-end files and copied to the server for deployment. I guess this is almost the same as #1 except the src/files directory needs to include the express.js application files and would allow me to run pre-processors on the back-end source.

3)我的后端应用程序requires docpad(生成out/目录并添加docpad中间件)然后启动服务器(如下所示:

3) My back-end application requires docpad (which generates the out/ directory and adds docpad middleware) then starts the server (something like shown here: https://github.com/bevry/docpad/issues/342). This would streamline testing but the entire project directory structure (src/, out/, and all) would need to be copied to the server for deployment.

我不是要问如何做到这一点的具体细节,而是想知道什么被认为是docpad的哲学.我还有其他选择吗?

I'm not asking specifics on how to do this but wondering what is considered the docpad philosophy on this. Is there another option I missed?

谢谢.

推荐答案

问题就变成了如何将服务器生成javascript(称为app.js)放置在哪里?在docpad.coffee旁边的项目文件夹根目录中还是在src/目录中?然后,如何在测试过程中让docpad代替内置服务器使用docpad.谢谢您的帮助

The question becomes where do I put the server generating javascript (call it app.js)? In the project folder root next to docpad.coffee or in the src/ directory? Then how do I get docpad to use this instead of the built-in server during testing. Thanks for your help

为此,您将创建app.js,其中包含与 API文档相关的内容到:

So to do that, you would create app.js that contains something like what the API docs pertain to:

var docpadInstanceConfiguration = {
    env: 'static'
};
require('docpad').createInstance(docpadInstanceConfiguration, function(err,docpadInstance){
    if (err)  return console.log(err.stack);
    var generateOpts = {};
    docpadInstance.action('generate', generateOpts, function(err,result){
        if (err)  return console.log(err.stack);
        // ...
    });
});

然后,您将更新Procfile(对于heroku)和package.json主条目(对于其他所有内容),使其指向app.js,而不是detault ./node_modules/.bin/docpad-server

You would then update your Procfile (for heroku) and your package.json main entry (for everything else) to point to app.js instead of the detault ./node_modules/.bin/docpad-server

如果要定义DocPad应该使用的自己的Express服务器,还可以通过docpadInstanceConfigurationserverHttpserverExpress传递到docpad. 此处有更多信息.

You can also pass over serverHttp and serverExpress to docpad via the docpadInstanceConfiguration if you want to define your own express server that DocPad should use. More info here.

这篇关于集成express.js应用程序和docpad的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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