heroku 我收到空白页后,我已经部署了我的应用程序

8yparm6h  于 2024-01-08  发布在  其他
关注(0)|答案(1)|浏览(213)

我需要帮助我的React应用程序。在完成我在React中开发的应用程序后,由于性能问题,我决定使用Vite内部。
当我构建并尝试预览时,所有集成在我的本地环境中运行良好,但由于部署在Heroku上,我有一个空白页,有人帮助我。
前端:

  1. "scripts": {
  2. "start": "serve -s build",
  3. "dev": "vite",
  4. "build": "tsc && vite build",
  5. "test": "vite test",
  6. "eject": "vite eject",
  7. "preview": "vite preview"
  8. }

字符串
后端:

  1. "scripts": {
  2. "data:import": "ts-node ./src/models/seeder.model.ts",
  3. "data:destroy": "ts-node src/models/seeder.model.ts -d",
  4. "test": "echo \"Error: no test specified\" && exit 1",
  5. "start": "node dist/server.js",
  6. "postinstall": "tsc ",
  7. "tsc": "./node_modules/typescript/bin/tsc",
  8. "watch-node": "nodemon dist/server.js",
  9. "server": "nodemon ./src/server.ts ",
  10. "client": "npm start --prefix fa-shop",
  11. "watch-ts": "tsc -w",
  12. "deploy": "git add . && git commit -m Heroku && git push heroku main",
  13. "heroku-postbuild": " npm install --prefix fa-shop && npm run build --prefix fa-shop",
  14. "dev": "concurrently \"npm run server\" \"npm run client \" "
  15. }


和文件夹是这样组织的

  1. appBackend --
  2. -- node_modules/backend
  3. -- frondend
  4. --- node_modules/frontend


图像来源:Heroku

x3naxklr

x3naxklr1#

最后我解决了这个问题,问题是与核心策略(cors())和内容安全策略(CSP),我做了一些更新,在我的vite文件太

  1. proxy: {
  2. '/api': {
  3. target: `https://fashopapp-c129f80f4143.herokuapp.com`,
  4. changeOrigin: true,
  5. secure: false,
  6. ws: true,
  7. },
  8. },
  9. hmr: { overlay: false }

字符串
然后在我的服务器文件中添加这个配置的cors包

  1. app.use(
  2. cors({
  3. origin: 'https://fashopapp-c129f80f4143.herokuapp.com/ ',
  4. methods: ['GET', 'POST', 'PUT', 'DELETE'],
  5. allowedHeaders: ['Authorization', 'Content-Type'],
  6. maxAge: 86400,
  7. })
  8. )


和CSP

  1. app.use((req, res, next) => {
  2. res.setHeader(
  3. 'Content-Security-Policy',
  4. "style-src-elem 'self'"
  5. )
  6. next()
  7. })


我认为这对某人有帮助。

展开查看全部

相关问题