我想使用Javascript将文件上传到Firebase的Google云端存储。问题是我正在使用npm run dev
在本地服务器上测试它,显然这不允许我将文件上传到FB存储位置(看起来像gs://xyz.appspot.com
),因为交叉原始请求阻止。
所以,根据this recommendation,我现在正在尝试使用Node的http-server模块建立一个http服务器。我的项目由Webpack生成,输出文件位于dist
。在dist
内我运行http-server index.html
,我看到了:
Starting up http-server, serving index.html
Available on:
http://127.0.0.1:8080
http://192.XXX:8080
Hit CTRL-C to stop the server
[Fri May 05 2017 08:23:37 GMT+0200 (CEST)] "GET /__webpack_hmr" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) xAppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
[Fri May 05 2017 08:23:37 GMT+0200 (CEST)] "GET /__webpack_hmr" Error (404): "Not found"
最后两条消息不断重复。
我转到localhost地址,找不到页面(404错误)。任何想法我的节点服务器出了什么问题?
编辑:
实际上,http-server采用了要提供的文件的路径,所以我应该一直在使用:
http-server ./
这是webpack配置:
var path = require('path')
module.exports = {
build: {
env: require('./prod.env'),
index: path.resolve(__dirname, '../dist/index.html'),
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: '/',
productionSourceMap: true,
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin
productionGzip: false,
productionGzipExtensions: ['js', 'css'],
// Run the build command with an extra argument to
// View the bundle analyzer report after build finishes:
// `npm run build --report`
// Set to `true` or `false` to always turn it on or off
bundleAnalyzerReport: process.env.npm_config_report
},
dev: {
env: require('./dev.env'),
port: 8080,
autoOpenBrowser: true,
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {},
// CSS Sourcemaps off by default because relative paths are "buggy"
// with this option, according to the CSS-Loader README
// (https://github.com/webpack/css-loader#sourcemaps)
// In our experience, they generally work as expected,
// just be aware of this issue when enabling this option.
cssSourceMap: false
}
}
此仍然无法解决我的问题。页面加载,但我得到相同的跨源错误。