我使用express创建简单的webrtc应用程序,并使用npm start将其工作节点本地化,但是当我部署到now.sh时,我的应用程序无法从node_modules加载任何脚本
我的server.js / index.js
const express = require('express');
const app = express();
const port = 8000;
// Set public folder as root
app.use(express.static(__dirname +'/public'));
// Provide access to node_modules folder from the client-side
app.use('/scripts', express.static(`${__dirname}/node_modules`));
// Redirect all traffic to index.html
app.route('/*').get((req, res) => res.sendFile(`${__dirname}/public/index.html`));
app.listen(port, () => {
console.info('listening on %d', port);
});
package.json
{
"name": "webrtc",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"@andyet/simplewebrtc": "^1.16.0",
"express": "^4.17.1",
"handlebars": "^4.7.3",
"jquery": "^3.4.1",
"semantic-ui-css": "^2.4.1",
"simplewebrtc": "^3.0.2"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"keywords": [],
"author": "good",
"license": "ISC"
}
now.json
{
"version": 2,
"builds": [{ "src": "index.js", "use": "@now/node-server" }]
}
不建议在平台上使用此用法。如果您真的想尝试一下,最好的选择是: