问题描述
我已将网站部署到Google Cloud Platform,并且react(static)部分工作正常,但是每当我转到/ api / mail / send以使用nodemailer时,我都会收到404错误消息,提示找不到该代码或yaml文件中的一些配置,我只是出现500错误。以下是我的yaml,package.json和server.js文件
runtime: nodejs12
env: standard
basic_scaling:
max_instances: 5
idle_timeout: 5m
handlers:
- url: /api/.*
secure: always
script: auto
- url: /
static_files: client/build/index.html
upload: client/build/index.html
secure: always
- url: /
static_dir: client/build
secure: always
Package.json
{
"name": "mern","version": "1.0.0","description": "","main": "server.js","scripts": {
"start": "node server.js","dev": "concurrently \"nodemon --ignore 'client/*'\" \"npm run client\"","client": "cd client && npm run start","install": "cd client && npm install","build": "cd client && npm run build"
},"author": "","license": "ISC","devDependencies": {
"autoprefixer": "^9.8.6","concurrently": "^5.3.0","husky": "^4.2.5","postcss-cli": "^7.1.1","tailwindcss": "^1.6.2"
},"dependencies": {
"if-env": "^1.0.4","axios": "^0.19.2","body-parser": "^1.19.0","classnames": "^2.2.6","dotenv": "^8.2.0","express": "^4.17.1","express-session": "^1.17.1","morgan": "^1.10.0","nodemailer": "^6.4.11"
}
}
server.js
require('dotenv').config()
const express = require("express");
const morgan = require('morgan');
const routes = require("./routes");
const path = require('path');
const app = express();
const PORT = process.env.PORT || 3001;
// Define middleware here
app.use(morgan('dev'));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
// Add routes,both API and view
app.use(routes);
// Serve up static assets (usually on heroku)
app.use(express.static("client/build"));
// Start the API server
app.listen(PORT,function() {
console.log(`? ==> API Server Now listening on PORT ${PORT}!`);
});
谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)