簡體   English   中英

AgoraIO Web + Heroku

[英]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 文件解決了這個問題(來自另一個repo):

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);
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM