Express.statische() funktioniert nicht
Habe ich folgende server-code:
var express = require('express');
var webpack = require('webpack');
var app = express();
//app.use(express.static(path.join(__dirname, "public")));
app.use("/", express.static(__dirname + "/public"));
//both not working. I have tried multiple ways....
app.get("/",function (req, res){
res.sendFile(__dirname + "/public/index/index.html")
});
app.listen(3000);
Webpack configs
module.exports = {
entry: './app/index/index.js',
output: {
path: path.resolve(__dirname, 'public/index'),
publicPath: '/public/index',
filename: 'index_bundle.js'
},
module: {
rules: [
{ test: /\.(js)$/, use: 'babel-loader' },
{ test: /\.css$/, use: [ 'style-loader', 'css-loader' ]}
]
},
plugins: [
new HtmlWebpackPlugin({
template: 'app/index/index.html'
})
]};
Folgende Verzeichnis-Struktur:
-public
-index
-index_bundle.js
Bekomme ich die folgende Fehlermeldung, wenn ich versuche zu laden meine index_bundle js:
BEKOMMEN http://localhost:3000/public/index/index_bundle.js 404 (Nicht Gefunden)
Ich kann es nicht reparieren und ich fand keine Lösung auf dem web.
- gibt es einen Ordner mit dem Namen index, in dem index_bundle.js wohnt?
Du musst angemeldet sein, um einen Kommentar abzugeben.
Ändern
zu
Können Sie
DEBUG=* node <your-server-file>.js
zum Debuggen solcher express-Fragen.Besser mehr sichere Lösung:
app.use('/public', express.static(__dirname + '/public'))
.