简体   繁体   English

如何在以下条件下提供我的静态文件

[英]how to serve my static files in condition below

在此处输入图片说明

router.use(express.static('public'));

router.get('/edit-page/:slug',function(req, res){

    Page.findOne({slug: req.params.slug}, function(err, page) {
        if(err)
            return console.log(err);

        res.render('admin/edit_page', {
            title: page.title,
            slug: page.slug,
            content : page.content,
            id: page._id
        });

There are multiple ways to do it -有多种方法可以做到——

1. Read the HTML file and send it to the client. 1. 读取 HTML 文件并将其发送给客户端。

    app.get('/', (req, res) => {
      fs.readFile(__dirname + '/public/index.html', 'utf8', (err, text) => {
        res.send(text);
      });
   });

2. You can have a jade or EJS template engine. 2. 你可以有一个 jade 或 EJS 模板引擎。 include a plain HTML page:包括一个纯 HTML 页面:

in views/index.jade在视图/index.jade

include plain.html
in views/plain.html

... and app.js can still just render jade: ...而 app.js 仍然可以渲染 jade:

res.render(index)

Note - set the engine type in your app.js file注意 - 在 app.js 文件中设置引擎类型

app.set("view engine","jade")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM