gpt4 book ai didi

javascript - 使用 express 将 css 包含到 html

转载 作者:行者123 更新时间:2023-11-28 08:31:12 25 4
gpt4 key购买 nike

我想在我的简单 html 页面中包含一个 css 表。我正在使用 parse.com 托管来托管使用 express 的动态网页。

关于这个问题有很多答案,但似乎没有一个对我有用。

我试图用这行代码从我的 .ejs 页面中包含我的 css 文件

<link rel="stylesheet" type="text/css" href="css/content.css" />

我将我的 css 文件夹复制到公共(public) floder 中

最推荐的答案是添加这行代码:

 app.use(express.static(__dirname + '/public'));

但是没有用。

var express = require('express');
var app = express();
app.use(express.static(__dirname + '/public'));
// Global app configuration section
app.set('views', 'cloud/views'); // Specify the folder to find templates
app.set('view engine', 'ejs'); // Set the template engine


app.use(express.bodyParser()); // Middleware for reading request body



// This is an example of hooking up a request handler with a specific request
// path and HTTP verb using the Express routing API.

app.get('/content/:id', function(req, res) {


res.render('content', {message: "hi"});

});

我正在按照本指南设置 express : https://www.parse.com/docs/hosting_guide#webapp-started

当我尝试部署我的代码时,我收到此错误“更新失败,无法加载触发器。错误是 ReferenceError:__dirname 未定义”

我在这里做错了什么?

最佳答案

在研究这个问题一段时间后,我在 parse.com 网站上阅读了这个。

"our Express app can sit side-by-side with any static content you deployed from your public folder. When a request goes to a URL of your subdomain, Parse will first look for a matching file in the public directory. If there is no match, then Parse will invoke any Express request handlers that you have registered in Cloud Code. If there is still no match, Parse will render a "404 Not Found" page."

关于javascript - 使用 express 将 css 包含到 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28262291/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com