如何解决AgoraIO Web + Heroku
我正在尝试将github repo LargeGroupVideoChat-Web-Webpack推送到Heroku。 在本地工作正常,使用以下脚本在package.json文件中:
"scripts": {
"dev": "cross-env NODE_ENV=development webpack-dev-server --config ./scripts --mode development","build": "cross-env NODE_ENV=production webpack --config ./scripts --mode production"},
以及index.js文件中的webpack设置:
module.exports = {
entry: {
index: "./src/index.js",},devtool: "inline-source-map",module: loaders,plugins,resolve: {
extensions: [ ".js" ],output: {
filename: "[name].[hash].js",path: path.resolve(__dirname,distPath),...
但是,在推送到Heroku之后,它崩溃并显示错误。我用以下代码添加了server.js文件:
const express = require('express');
const path = require('path');
const port = process.env.PORT || 8080;
const app = express();
// the __dirname is the current directory from where the script is running
app.use(express.static(__dirname));
// send the user to index html page inspite of the url
app.get('*',(req,res) => {
res.sendFile(path.resolve(__dirname,'index.html'));
});
app.listen(port);
运行正常,但仅提供index.html文件,并且未捆绑webpack捆绑包。是否有将应用程序推送到Heroku的快速方法?还是我必须以某种方式重写Webpack设置?
解决方法
好的,server.js文件解决了该问题(来自another回购):
var path = require('path');
var express = require('express');
var app = express();
app.use(express.static(path.join(__dirname,'dist')));
app.set('port',process.env.PORT || 8080);
var server = app.listen(app.get('port'),function() {
console.log('listening on port ',server.address().port);
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。