/api/auth 404(未找到)

编程入门 行业动态 更新时间:2024-10-03 02:14:36

/api/auth 404(<a href=https://www.elefans.com/category/jswz/34/1771447.html style=未找到)"/>

/api/auth 404(未找到)

我需要更改我的 nginx/sites-available/default 配置什么才能找到 /api/auth?我是 nginx 的新手。我认为问题出在用于将请求代理到 api 的 nginx 配置中。这是我的 /nginx/sites-available/default 配置:

  server {
  listen 80 default_server;
  server_name _;

  # react app & front-end files
  location / {
    root /opt/devParty/client/build;
    try_files $uri /index.html;
  }

  # node api reverse proxy
  location /api {
    root /opt/devParty/routes/api;
    try_files $uri /api/auth.js =404;
    add_header 'Access-ControlAllow-Origin' '*';
    proxy_pass http://localhost:4000/;
     }
   }

这里是 EC2 ubuntu 上的文件结构:

devParty/
├── client
│   ├── package-lock.json
│   ├── package.json
│   └── webpack.config.js
├── config
│   ├── db.js
│   └── default.json
├── middleware
│   └── auth.js
├── models
│   ├── Post.js
│   ├── Profile.js
│   └── User.js
├── package-lock.json
├── package.json
├── routes
│   └── api
└── server.js

还有我的 server.js 文件:

const { application } = require('express')
const express = require('express')
const app = express()
const PORT = process.env.PORT || 4000
const connectDB = require('./config/db')
const path = require('path')

// Connect Database
connectDB()

// Init Midddleware
// Allows us to get data in req.body on users.js
app.use(express.json({ extended: false }))

// app.get('/', (req, res) => res.send('API Running'))

// Define Routes
app.use('/api/users', require('./routes/api/users'))
app.use('/api/auth', require('./routes/api/auth'))
app.use('/api/profile', require('./routes/api/profile'))
app.use('/api/posts', require('./routes/api/posts'))

// Server status assets in production
if(process.env.NODE_ENV === 'production') {
    // Set static foler
    app.use(express.static('client/build'))

    app.get('*', (req, res) => {
        res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html')) })
}

app.listen(PORT, () => console.log(`Server started on port ${PORT}`))
回答如下:

更多推荐

/api/auth 404(未找到)

本文发布于:2024-05-30 16:22:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770688.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:未找到   api   auth

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!