3

クライアントのpackage.jsonでプロキシを使用しようとしたノードに反応するようにプロキシをセットアップしようとしましたが、getメソッドを使用しようとするとエラーが発生し続けるため、別のソリューションを検索し、このnpmを使用してこれを見つけましたモジュール (http-proxy-middleware) を実行し、npm cache clean --force コマンドを実行してすべてのキャッシュをクリアします。これにより、誰でもこのエラーの内容を教えてくれます。または、アプリを正常に動作させる方法が他にある場合は、

これは私のserver.jsファイルです

const express = require('express');
const connectDB = require('./config/db');
const app = express();

//connect database
connectDB();

// Init Middelware
app.use(express.json({ extended: false }));

const port = process.env.PORT || 6000;

app.get('/', (req, res) => {
  res.send('api running');
});

// Define route
app.use('/api/users', require('./router/api/user'));

app.use('/api/posts', require('./router/api/post'));

app.use('/api/profile', require('./router/api/profile'));

app.use('/api/auth', require('./router/api/auth'));

app.listen(port, () => {
  console.log(`server started in port ${port}`);
});

これは私のsetupProxy.jsファイルです

const proxy = require('http-proxy-middleware');
module.exports = function(app) {
  app.use(
    '/api',
    proxy({
      target: 'http://localhost:6000',
      changeOrigin: true
    })
  );
};

しかし、それは私に別の問題をもたらしました

[1] proxy is not a function
[1] npm ERR! code ELIFECYCLE
[1] npm ERR! errno 1
[1] npm ERR! social-app@0.1.0 start: `react-scripts start`
[1] npm ERR! Exit status 1
[1] npm ERR!
[1] npm ERR! Failed at the social-app@0.1.0 start script.
[1] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
[1]
[1] npm ERR! A complete log of this run can be found in:
[1] npm ERR!     C:\Users\hp\AppData\Roaming\npm-cache\_logs\2020-03-19T10_53_44_499Z-debug.log
[1] npm ERR! code ELIFECYCLE
[1] npm ERR! errno 1
[1] npm ERR! social-app@1.0.0 client: `npm start --prefix social-app`
[1] npm ERR! Exit status 1
[1] npm ERR!
[1] npm ERR! Failed at the social-app@1.0.0 client script.
[1] npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
[1]
[1] npm ERR! A complete log of this run can be found in:
[1] npm ERR!     C:\Users\hp\AppData\Roaming\npm-cache\_logs\2020-03-19T10_53_44_587Z-debug.log
[1] npm run client exited with code 1
4

1 に答える 1