我不是第一次使用Express并渲染模板视图,但最近我尝试了一个新的目录结构,这似乎让我的应用程序实例感到困惑。
它不再提供我的静态引导、CSS和图像
文件,现在我的视图看起来很混乱。
以下是我的目录结构:
AppName
- node_modules folder
- src (all code live here)
- public (statics)
- css/mycss, bootstrapcss
- js/ myjs, bootstrapjs
- images folder
- models
- app.js (entry point)
静态文件似乎比根目录深两个级别。在我的app.js
文件中,我尝试使用express static method
,如下所示:
app.use( express.static(path.join(__dirname, './src' + '/public')));
我也尝试了这个:
app.use('/src', express.static(path.join(__dirname, '/public')));
在我的看法中,例如静态文件的调用方式如下:
<link href="../public/css/bootstrap.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="../public/fonts/glyphicons-halflings-regular.ttf">
<link rel="stylesheet" href="../public/css/styles.css" type="text/css">
<script defer src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
<script src="https://cdn.ckeditor.com/ckeditor5/1.0.0-alpha.2/classic/ckeditor.js"></script>
但是我仍然无法将这些文件提供给我的视图。我卡在这里了。 有人能帮帮我吗?谢谢。
app.js
中尝试只使用app.use(express.static('public'));
。 - mmmmycss
和bootstrapcss
等是文件还是目录? - devius