无法使用+ mqql部署heroku

时间:2019-06-04 11:18:37

标签: reactjs

我正在使用MERN + GRAPH QL创建一个全栈Web应用程序,但是当部署到heroku时 缺少GET查询。

它显示了,并且显示不正常。

部署日志在这里

-----> Node.js app detected

-----> Creating runtime environment

NPM_CONFIG_LOGLEVEL=error
NODE_ENV=production
NODE_MODULES_CACHE=true
NODE_VERBOSE=false

-----> Installing binaries
engines.node (package.json):  v10.15.3
engines.npm (package.json):   v6.4.1
engines.yarn (package.json):  v1.15.2

Resolving node version v10.15.3...
Downloading and installing node 10.15.3...
Bootstrapping npm v6.4.1 (replacing 6.4.1)...
npm v6.4.1 installed
Resolving yarn version v1.15.2...
Downloading and installing yarn (1.15.2)...
Installed yarn 1.15.2

-----> Restoring cache

node_modules
-----> Installing dependencies
Installing node modules (yarn.lock)
yarn install v1.15.2
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.62s.

-----> Build
Running heroku-postbuild (yarn)
yarn run v1.15.2
$ NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client

core-js@2.6.9 postinstall /tmp/build_d5c70a66310676d67abc805c1a172941/client/node_modules/babel-runtime/node_modules/core-js
node scripts/postinstall || echo "ignore"

core-js-pure@3.1.3 postinstall /tmp/build_d5c70a66310676d67abc805c1a172941/client/node_modules/core-js-pure
node scripts/postinstall || echo "ignore"

added 1464 packages from 846 contributors and audited 889284 packages in 56.855s
found 0 vulnerabilities

client@0.1.0 build /tmp/build_d5c70a66310676d67abc805c1a172941/client
react-scripts build

Creating an optimized production build...
Compiled with warnings.

./src/components/Habits/MyHabits.js
Line 17:  React Hook useEffect has missing dependencies: 'currentUser' and 'history'. Either include them or remove the dependency array  react-hooks/exhaustive-deps

./src/components/Habits/StarButton.js
Line 19:  React Hook useEffect has missing dependencies: 'currentUser' and 'habit._id'. Either include them or remove the dependency array  react-hooks/exhaustive-deps

./src/components/Habits/StarLabel.js
Line 20:  React Hook useEffect has missing dependencies: 'currentUser' and 'habit._id'. Either include them or remove the dependency array  react-hooks/exhaustive-deps

Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.

File sizes after gzip:

257.66 KB  build/static/js/2.8fc707a7.chunk.js
97.2 KB    build/static/css/2.621b5bde.chunk.css
9.7 KB     build/static/js/main.d52bf224.chunk.js
886 B      build/static/css/main.15b794e3.chunk.css
762 B      build/static/js/runtime~main.a8a9905a.js

The project was built assuming it is hosted at the server root.
You can control this with the homepage field in your package.json.
For example, add this to build it for GitHub Pages:

"homepage" : "http://myname.github.io/myapp",

The build folder is ready to be deployed.
You may serve it with a static server:

yarn global add serve
serve -s build

Find out more about deployment here:




Done in 135.78s.

-----> Caching build

node_modules
-----> Pruning devDependencies
yarn install v1.15.2
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.9: The platform "linux" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > react-infinite-scroller@1.2.4" has unmet peer dependency "react@^0.14.9 || ^15.3.0 || ^16.0.0".
warning " > react-spinners@0.5.4" has unmet peer dependency "react@^16.0.0".
warning " > react-spinners@0.5.4" has unmet peer dependency "react-dom@^16.0.0".
warning "react-spinners > @emotion/core@10.0.10" has unmet peer dependency "react@>=16.3.0".
warning "react-spinners > recompose@0.30.0" has unmet peer dependency "react@^0.14.0 || ^15.0.0 || ^16.0.0".
[4/4] Building fresh packages...
warning Ignored scripts due to flag.
Done in 24.36s.

-----> Build succeeded!
!     Unmet dependencies don't fail yarn install but may cause runtime issues
https://github.com/npm/npm/issues/7494
-----> Discovering process types
Procfile declares types     -> (none)
Default types for buildpack -> web
-----> Compressing...
Done: 71.8M
-----> Launching...
Released v34
https://manehabi.herokuapp.com/ deployed to Heroku

package.json在这里。它直接放在根下。同样,它也位于server.js的正下方。

{
"name": "manehabi",
"scripts": {
"start": "node server.js",
"server": "nodemon server.js",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client \"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
},
"engines": {
"node": "v10.15.3",
"npm": "v6.4.1",
"yarn": "v1.15.2"
},
"version": "1.0.0",
"main": "server.js",
"license": "MIT",
"dependencies": {
"apollo-server": "^2.5.0",
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.0",
"graphql": "^14.3.1",
"jsonwebtoken": "^8.5.1",
"md5": "^2.2.1",
"moment": "^2.24.0",
"mongoose": "^5.5.11",
"react-infinite-scroller": "^1.2.4",
"react-spinners": "^0.5.4"
},
"devDependencies": {
"concurrently": "^4.1.0",
"nodemon": "^1.19.0"
}
}
const express = require("express");
const { ApolloServer } = require("apollo-server");
const typeDefs = require("./typeDefs.graphql");
const resolvers = require("./resolvers");
const mongoose = require("mongoose");
const jwt = require("jsonwebtoken");
const path = require("path");
const bodyParser = require("body-parser");

const app = express();

app.use(bodyParser());

const db = require("./config/keys").mongoURI;
const secret = require("./config/keys").secret;

mongoose
.connect(db, { useNewUrlParser: true })
.then(() => console.log("MongoDB Connected"))
.catch(err => console.log(err));

const server = new ApolloServer({
    typeDefs,
    resolvers,
    context: async ({ req }) => {
        let token = null;
        let currentUser = null;

        try {
            token = req.headers["authorization"];
             if (token) {
                 currentUser = await jwt.verify(token, secret);
                 }
        } catch (err) {
             console.error(Unable to authenticate user with token);
        }
          return { currentUser };
    }

});

 // Server static assets if in production
if (process.env.NODE_ENV === "production") {
// Set static folder

app.use(express.static("client/build"));

app.get("*", (req, res) => {
console.log("hi there");
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});

}

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

server.listen({ port }).then(({ url }) => {
    console.log(?  Server ready at ${url});
});

客户端文件夹是在相同的层次结构中创建的。

即使您查看git log,服务器似乎也能正常工作,所以我认为获取react的index.html并不是很好。

1 个答案:

答案 0 :(得分:0)

嗨,你可以尝试

L