我在 server.js 中有这个
//socket io config
const server = require('http').createServer(app)
const io = require('socket.io')(server)
io.on('connection', function (socket) {
socket.on('SOCKET_COMMENT_RECEIVED', ({ notification }) => {
io.emit(`SOCKET_COMMENT_RECEIVED`, notification)
})
//and many more
})
Run Code Online (Sandbox Code Playgroud)
在我的客户端(反应)
import io from 'socket.io-client'
const socket = io('localhost:3001') // working in localhost
Run Code Online (Sandbox Code Playgroud)
在我的产品中我做了这个检查
let socket = io('localhost:3001')
if(process.env.NODE_ENV === 'production') { socket =
io('https://api.example.com:3001')
}
Run Code Online (Sandbox Code Playgroud)
为什么会这样呢?我不认为这是 cors 问题,因为我已经这样做了
app.use(cors({
origin: true,
credentials: true
}))
Run Code Online (Sandbox Code Playgroud)
我的 package.json 依赖项
"socket.io": "^2.1.1",
"socket.io-client": "^2.1.1",
Run Code Online (Sandbox Code Playgroud) Gatsby 和 Netlify CMS 运行良好一段时间,但现在尝试运行时失败gatsby develop。出现“JavaScript 堆内存不足”错误。
每个 npm 都会更新,我已经尝试export NODE_OPTIONS=--max_old_space_size=4096过一些 GitHub 问题线程提到的。
我想练习创建自己的 RESTful API 服务,以配合我创建的客户端应用程序。我的计划是使用 Node 和 Express 来创建服务器。在我的本地计算机上,我知道如何设置本地服务器,但我希望能够在线托管我的应用程序(客户端和服务器)作为我的投资组合的一部分。
我的客户端应用程序发送到服务器的数据大小不会很大,因此不需要数据库。只需让我的服务器将接收到的数据动态保存在数组中就足够了,并且如果用户退出网页,我不会关心该数据是否持续存在。
是否可以使用 Netlify 之类的服务来托管客户端和服务器以实现我的目的?我正在想象类似如何在我的计算机上启动本地开发服务器以便前端可以与其交互的方式。但现在我希望所有内容都在线托管以供其他人查看。我计划在与前端代码相同的存储库中创建 Express 服务器。
我可以通过在搜索栏中输入 url 来更改托管在 netlify(手动部署)上的 flutter web的 url ,从而导航到其他页面,如下所示:-

因此,如果我将 /home 更改为 /about 那么它会完美地引导我到 about 页面。但是为了从我的网址中删除这个“#”,我在我的 main.dart我的代码中添加了以下代码 :-
import 'package:url_strategy/url_strategy.dart';
void main()async {
await Firebase.initializeApp();
setPathUrlStrategy();//this removes the '#' from my url
FluroRouting.setupRouter();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'My Website',
theme: ThemeData(
primarySwatch: Colors.blue,
),
initialRoute: '/home',
onGenerateRoute: FluroRouting.router.generator,
);
}
}
Run Code Online (Sandbox Code Playgroud)
路由代码是:-
class FluroRouting {
static final router = FluroRouter();
static Handler _aboutUsHandler = …Run Code Online (Sandbox Code Playgroud) 我尝试将我的 Gatsby 站点部署到 Netlify,但每当我尝试部署时,我总是收到各种节点模块的这些错误。我尝试制作一个 webpack.config.js 文件并包含两个建议的解决方案,但均无济于事。我还尝试使用别名而不是后备,将浏览器部分添加到 package.json 文件中,将模块设置为 false,并按照其他一些 stackoverflow 答案的建议在 webpack.config.js 文件中添加目标属性,但是我还是很困惑。我之前没有任何 webpack 经验,并且一直在尽力寻找答案。我缺少 Gatsby 的某种特殊配置吗?
错误信息
10:37:20 AM: error Generating JavaScript bundles failed
10:37:20 AM: Can't resolve 'stream' in '/opt/build/repo/node_modules/cipher-base'
10:37:20 AM: If you're trying to use a package make sure that 'stream' is installed. If you're trying to use a local file make sure that the path is correct.
10:37:20 AM: BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
10:37:20 …Run Code Online (Sandbox Code Playgroud) 我过去已经这样做过很多次了,我在 netlify 日志中收到此错误。我尝试部署的存储库是https://github.com/yanyamz/Key_Visual_Arts。
\n我检查了它是否在 Netlify 的大小限制内,结果是,总共 15mb 左右,而您可以在 netlify 上部署的 20+mb 左右。
\n12:03:03 PM: Build ready to start\n12:03:04 PM: build-image version: fa439ad1ab9393b2c0d449d8d7c033927683f4b0\n12:03:04 PM: build-image tag: v4.3.0\n12:03:04 PM: buildbot version: 0f2f658d862cfe72bae7cc05c6a8de0426a5a0e2\n12:03:04 PM: Fetching cached dependencies\n12:03:05 PM: Failed to fetch cache, continuing with build\n12:03:05 PM: Starting to prepare the repo for build\n12:03:05 PM: No cached dependencies found. Cloning fresh repo\n12:03:05 PM: git clone https://github.com/yanyamz/Key_Visual_Arts\n12:03:07 PM: Preparing Git Reference refs/heads/main\n12:03:07 PM: Parsing package.json dependencies\n12:03:08 PM: \n\xe2\x80\x8b\n\xe2\x9d\xaf Initial build environment\nbaseRelDir: …Run Code Online (Sandbox Code Playgroud) 在我的索引页中,我正在使用serverSideTranslations函数。查找翻译文件时出现错误。此错误仅发生在使用 的页面上serverSideTranslations。
我部署到 Vercel 和 Netlify。在他们两个中我都遇到了同样的错误。
在_app.js我正在使用appWithTranslation.
依赖项:
"dependencies": {
"@fortawesome/fontawesome-free": "^5.15.4",
"@netlify/plugin-nextjs": "^3.9.2",
"axios": "^0.21.1",
"bootstrap": "^4.6.0",
"dayjs": "^1.10.4",
"dotenv": "^8.2.0",
"fs-extra": "^10.0.0",
"is-mobile": "^3.0.0",
"next": "^11.1.2",
"next-i18next": "^8.9.0",
"next-seo": "^4.20.0",
"node-fetch": "^2.6.1",
"parse": "^3.1.0",
"react": "17.0.1",
"react-bootstrap": "^1.5.0",
"react-dom": "17.0.1",
"react-infinite-scroller": "^1.2.4",
"recoil": "^0.1.2",
"sass": "^1.43.2",
"ts-node": "^9.1.1"
}
Run Code Online (Sandbox Code Playgroud)
next.config.js
const path = require('path');
const { PHASE_DEVELOPMENT_SERVER } = require('next/constants')
const i18NextConfig = require('./next-i18next.config');
const prodConfig = {
generateBuildId: () …Run Code Online (Sandbox Code Playgroud) 我可以npm run build毫无问题地运行,但每当我尝试将 Next.js 项目部署到 Netlify 时,我都会收到一个奇怪的错误,指出Deploy failed due to an error in @netlify/plugin-nextjs plugin
经过一些研究后,我发现我应该将其@netlify/plugin-nextjs作为开发依赖项安装到 package.json 中,然后将其添加到我已完成的项目根目录中的 netlify.toml 中。这是 Netlify 支持论坛引导我找到的 github 存储库: https: //github.com/netlify/netlify-plugin-nextjs
我已经按照上面他们的 github 存储库上的 @netlify/plugin-nextjs 插件的说明进行操作,并在他们的 github issues 下搜索了任何相关帖子,不幸的是,我无法\xe2\x80\x99 在 中找到任何相关或有用的内容。 github问题。
\n我\xe2\x80\x99已尝试清除缓存并部署,但它没有\xe2\x80\x99帮助。
\n我使用的是 Next.js 版本 v11.1.2
\n这是包含详细错误的构建日志:
\n11:58:50 PM: Started restoring cached go cache\n11:58:50 PM: Finished restoring cached go cache\n11:58:50 PM: go version go1.16.5 linux/amd64\n11:58:50 PM: go version go1.16.5 linux/amd64\n11:58:50 PM: Installing missing …Run Code Online (Sandbox Code Playgroud) 部署到 netlify 失败并出现 error: [vite]: Rollup failed to resolve import...,但当我使用本地构建时它可以工作npm run build(与 netlify 相同)。无法解析的包是直接从 github 安装的,而不是其他包。
包.json:
\n "dependencies": {\n "@tailwindcss/line-clamp": "^0.2.2",\n "focus-visible": "^5.2.0",\n "just-throttle": "^4.0.1",\n "lrud": "github:bbc/lrud#master",\n "sapper-environment": "^1.0.1"\n }\nRun Code Online (Sandbox Code Playgroud)\n网络化日志:
\n10:10:48 PM: \xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\n10:10:48 PM: 1. build.command from netlify.toml \n10:10:48 PM: \xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\n10:10:48 PM: \xe2\x80\x8b\n10:10:48 PM: $ npm run build\n10:10:48 PM: > sveltekit-movie-app@0.0.1 build\n10:10:48 PM: > svelte-kit build\n10:10:49 PM: vite v2.7.10 building for production...\n10:10:49 PM: transforming...\n10:10:52 PM: \xe2\x9c\x93 54 modules transformed.\n10:10:52 PM: [vite]: Rollup …Run Code Online (Sandbox Code Playgroud) 我需要重定向到 Netlify 上的一个 React 项目的主页,但我使用的是 vite。
我曾经使用 CRA (create-react-app) 来完成此操作,并使用此配置在公共文件夹中创建_redirects文件。
/* /index.html 200
Run Code Online (Sandbox Code Playgroud)
我该如何在vitejs中做到这一点?
netlify ×10
deployment ×2
gatsby ×2
javascript ×2
next.js ×2
node.js ×2
vite ×2
express ×1
flutter ×1
flutter-web ×1
netlify-cms ×1
next-i18next ×1
react-router ×1
reactjs ×1
rollup ×1
socket.io ×1
sockets ×1
svelte ×1
vercel ×1
vue.js ×1
webpack ×1