- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我编写了一个简单的 SSR Next js 网页,其中附加了一个 Express 服务器来处理我附加到联系表单的一些电子邮件功能。
我已经尝试部署到现在,虽然终端说我已经成功完成,但当我向我的 Express 服务器发出网络请求时,我收到 502 错误。
now.json:
{
"version": 2,
"builds": [
{"src": "package.json", "use": "@now/next"},
{"src": "/server/index.js", "use": "@now/node-server"}
],
"routes": [{"src": "/api/contact", "dest": "/server/index.js"}]
}
next.config.js:
const { PHASE_PRODUCTION_SERVER } =
process.env.NODE_ENV === 'development'
? {} // We're never in "production server" phase when in development mode
: !process.env.NOW_REGION
? require('next/constants') // Get values from `next` package when building locally
: require('next-server/constants'); // Get values from `next-server` package when building on now v2
module.exports = (phase, { defaultConfig }) => {
if (phase === PHASE_PRODUCTION_SERVER) {
// Config used to run in production.
return {};
}
const withSass = require('@zeit/next-sass');
return withSass();
};
我查看了 now-examples,但不幸的是,这种特定的库组合没有得到体现,而且我作为程序员的技术不够熟练,无法自己理解它们的内部工作原理。
任何帮助将不胜感激。我的服务器代码是
INDEX.JS
const express = require('express');
const next = require('next');
const bodyParser = require('body-parser');
const mailer = require('./mailer/mailer.js');
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev })
const handle = app.getRequestHandler()
app.prepare().then(() => {
const server = express();
server.use(bodyParser.json());
server.get('*', (req, res) => {
return handle(req, res);
});
server.post('/api/contact', (req, res) => {
const { firstName, lastName, phoneNumber, emailAddress, messageText } = req.body
mailer.send( firstName, lastName, phoneNumber, emailAddress, messageText ).then(() => {
console.log(`Sent the message "${messageText}" from <${firstName}> ${emailAddress}.`);
res.status(200);
res.send('success')
}).catch((error) => {
console.log(`Failed to send the message "${messageText}" from <${firstName}> ${emailAddress} with the error ${error && error.message}`);
res.status(400);
res.send('failure')
})
});
server.listen( (process.env.PORT || 3000) , (err) => {
if (err) throw err
console.log('> Read on http://localhost:3000')
});
});
我的 next.js 应用程序的其余部分非常简单。
日志:
2019-03-19T11:01:49.575Z [11:01:49] Compiling client
2019-03-19T11:01:49.598Z [11:01:49] Compiling server
2019-03-19T11:01:52.602Z [11:01:52] Compiled server in 3s
2019-03-19T11:02:00.177Z info fsevents@1.2.7: The platform "linux" is incompatible with this module.
2019-03-19T11:02:00.177Z info "fsevents@1.2.7" is an optional dependency and failed compatibility check. Excluding it from installation.
2019-03-19T11:02:00.183Z [3/4] Linking dependencies...
2019-03-19T11:02:00.199Z warning "@zeit/next-sass > sass-loader@6.0.6" has unmet peer dependency "webpack@^2.0.0 || >= 3.0.0-rc.0 || ^3.0.0".
2019-03-19T11:02:00.200Z warning "@zeit/next-sass > @zeit/next-css > css-loader@1.0.0" has unmet peer dependency "webpack@^4.0.0".
warning "@zeit/next-sass > @zeit/next-css > mini-css-extract-plugin@0.4.3" has unmet peer dependency "webpack@^4.4.0".
2019-03-19T11:02:00.208Z warning "next-optimized-images > raw-loader@1.0.0" has unmet peer dependency "webpack@^4.3.0".
2019-03-19T11:02:00.209Z warning "next-optimized-images > file-loader@3.0.1" has unmet peer dependency "webpack@^4.0.0".
warning "next-optimized-images > url-loader@1.1.2" has unmet peer dependency "webpack@^3.0.0 || ^4.0.0".
2019-03-19T11:02:00.209Z warning " > react-loading@2.0.3" has unmet peer dependency "prop-types@^15.6.0".
2019-03-19T11:02:02.880Z [11:02:02] Compiled client in 13s
2019-03-19T11:02:03.396Z compiling entrypoint with ncc...
2019-03-19T11:02:06.428Z [4/4] Building fresh packages...
2019-03-19T11:02:08.530Z success Saved lockfile.
2019-03-19T11:02:08.538Z Done in 28.73s.
2019-03-19T11:02:08.806Z yarn cache v1.13.0
2019-03-19T11:02:11.332Z success Cleared cache.
2019-03-19T11:02:11.332Z Done in 2.54s.
2019-03-19T11:02:11.341Z running user script...
2019-03-19T11:02:11.342Z running "yarn run now-build"
2019-03-19T11:02:11.592Z yarn run v1.13.0
2019-03-19T11:02:11.670Z $ NODE_OPTIONS=--max_old_space_size=3000 next build --lambdas
2019-03-19T11:02:13.254Z [11:02:13] Compiling client
2019-03-19T11:02:15.907Z ncc: Module directory "/tmp/6b60c2d/user/node_modules/chokidar/lib" attempted to require "fsevents" but could not be resolved, assuming external.
2019-03-19T11:02:31.586Z downloading user files...
2019-03-19T11:02:31.679Z installing dependencies for user's code...
2019-03-19T11:02:31.680Z installing to /tmp/84eaca5/user/server
2019-03-19T11:02:35.826Z Browser assets sizes after gzip:
19.3 kB .next/static/0rX3****/pages/_app.js
12.3 kB .next/static/0rX3****/pages/_error.js
1.04 kB .next/static/0rX3****/pages/components/about/About.js
6.64 kB .next/static/0rX3****/pages/components/backtotopbutton/BackToTopButton.js
1.14 kB .next/static/0rX3****/pages/components/bookingcard/BookingCard.js
323 B .next/static/0rX3****/pages/components/bookingcard/components/calendlywidget/CalendlyWidget.js
8.31 kB .next/static/0rX3****/pages/components/contactcard/ContactCard.js
8.26 kB .next/static/0rX3****/pages/components/contactcard/components/contactform/ContactForm.js
6.55 kB .next/static/0rX3****/pages/components/landingcard/LandingCard.js
7.09 kB .next/static/0rX3****/pages/components/mapview/MapContainer.js
6.81 kB .next/static/0rX3****/pages/components/mapview/components/mapview/MapView.js
8.49 kB .next/static/0rX3****/pages/components/navbar/NavBar.js
7.91 kB .next/static/0rX3****/pages/components/navbar/components/burgermenu/BurgerMenu.js
478 B .next/static/0rX3****/pages/components/servicescard/ServicesCard.js
25.7 kB .next/static/0rX3****/pages/index.js
56.2 kB .next/static/chunks/commons.ebad****.js
154 B .next/static/chunks/styles.49ee****.js
3.01 kB .next/static/css/styles.ee9ce638.chunk.css
23.4 kB .next/static/runtime/main-44b4****.js
737 B .next/static/runtime/webpack-8917****.js
2019-03-19T11:02:35.830Z [11:02:35] Compiled client in 23s
2019-03-19T11:02:35.854Z [11:02:35] Compiling server
2019-03-19T11:02:36.469Z npm WARN
2019-03-19T11:02:36.470Z clevetoothdenture@1.0.0 No repository field.
2019-03-19T11:02:36.470Z npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
2019-03-19T11:02:36.470Z
2019-03-19T11:02:36.470Z up to date in 4.427s
2019-03-19T11:02:36.657Z npm
2019-03-19T11:02:36.658Z
2019-03-19T11:02:36.658Z WARN using --force
2019-03-19T11:02:36.658Z I sure hope you know what you are doing.
2019-03-19T11:02:36.773Z writing ncc package.json...
2019-03-19T11:02:36.773Z installing dependencies for ncc...
2019-03-19T11:02:36.773Z installing to /tmp/84eaca5/ncc
2019-03-19T11:02:36.938Z yarn install v1.13.0
2019-03-19T11:02:36.962Z [1/4] Resolving packages...
2019-03-19T11:02:36.983Z success Already up-to-date.
2019-03-19T11:02:36.985Z Done in 0.05s.
2019-03-19T11:02:37.152Z yarn cache v1.13.0
2019-03-19T11:02:37.173Z success Cleared cache.
2019-03-19T11:02:37.173Z Done in 0.03s.
2019-03-19T11:02:55.631Z [11:02:55] Compiled server in 20s
2019-03-19T11:02:55.737Z Done in 44.15s.
2019-03-19T11:02:55.743Z running npm install --production...
2019-03-19T11:02:55.743Z installing to /tmp/77afa5cd
2019-03-19T11:02:55.994Z yarn install v1.13.0
2019-03-19T11:02:56.142Z [1/4] Resolving packages...
2019-03-19T11:02:57.021Z [2/4] Fetching packages...
2019-03-19T11:03:10.921Z info fsevents@1.2.7: The platform "linux" is incompatible with this module.
2019-03-19T11:03:10.921Z info "fsevents@1.2.7" is an optional dependency and failed compatibility check. Excluding it from installation.
2019-03-19T11:03:10.931Z [3/4] Linking dependencies...
2019-03-19T11:03:10.939Z warning "@zeit/next-sass > sass-loader@6.0.6" has unmet peer dependency "webpack@^2.0.0 || >= 3.0.0-rc.0 || ^3.0.0".
2019-03-19T11:03:10.940Z warning "@zeit/next-sass > @zeit/next-css > css-loader@1.0.0" has unmet peer dependency "webpack@^4.0.0".
warning "@zeit/next-sass > @zeit/next-css > mini-css-extract-plugin@0.4.3" has unmet peer dependency "webpack@^4.4.0".
2019-03-19T11:03:10.949Z warning "next-optimized-images > file-loader@3.0.1" has unmet peer dependency "webpack@^4.0.0".
2019-03-19T11:03:10.950Z warning "next-optimized-images > raw-loader@1.0.0" has unmet peer dependency "webpack@^4.3.0".
2019-03-19T11:03:10.950Z warning "next-optimized-images > url-loader@1.1.2" has unmet peer dependency "webpack@^3.0.0 || ^4.0.0".
2019-03-19T11:03:10.950Z warning " > react-loading@2.0.3" has unmet peer dependency "prop-types@^15.6.0".
2019-03-19T11:03:13.518Z [4/4] Building fresh packages...
2019-03-19T11:03:13.567Z Done in 17.58s.
2019-03-19T11:03:13.834Z yarn cache v1.13.0
2019-03-19T11:03:16.398Z success Cleared cache.
2019-03-19T11:03:16.399Z Done in 2.57s.
2019-03-19T11:03:16.666Z preparing lambda files...
2019-03-19T11:03:16.840Z Creating lambda for page: "components/about/About.js"...
2019-03-19T11:03:16.841Z Creating lambda for page: "components/backtotopbutton/BackToTopButton.js"...
2019-03-19T11:03:16.841Z Creating lambda for page: "components/bookingcard/BookingCard.js"...
2019-03-19T11:03:16.842Z Creating lambda for page: "components/bookingcard/components/calendlywidget/CalendlyWidget.js"...
2019-03-19T11:03:16.842Z Creating lambda for page: "components/contactcard/components/contactform/ContactForm.js"...
2019-03-19T11:03:16.843Z Creating lambda for page: "components/contactcard/ContactCard.js"...
2019-03-19T11:03:16.843Z Creating lambda for page: "components/landingcard/LandingCard.js"...
2019-03-19T11:03:16.844Z Creating lambda for page: "components/mapview/components/mapview/MapView.js"...
2019-03-19T11:03:16.844Z Creating lambda for page: "components/mapview/MapContainer.js"...
2019-03-19T11:03:16.845Z Creating lambda for page: "components/navbar/components/burgermenu/BurgerMenu.js"...
2019-03-19T11:03:16.845Z Creating lambda for page: "components/navbar/NavBar.js"...
2019-03-19T11:03:16.845Z Creating lambda for page: "components/servicescard/ServicesCard.js"...
2019-03-19T11:03:16.846Z Creating lambda for page: "index.js"...
2019-03-19T11:03:17.851Z Created lambda for page: "components/about/About.js"
2019-03-19T11:03:18.495Z Created lambda for page: "components/backtotopbutton/BackToTopButton.js"
2019-03-19T11:03:19.099Z Created lambda for page: "components/bookingcard/BookingCard.js"
2019-03-19T11:03:19.668Z Created lambda for page: "components/bookingcard/components/calendlywidget/CalendlyWidget.js"
2019-03-19T11:03:20.169Z Created lambda for page: "components/contactcard/components/contactform/ContactForm.js"
2019-03-19T11:03:20.923Z Created lambda for page: "components/contactcard/ContactCard.js"
2019-03-19T11:03:21.383Z Created lambda for page: "components/landingcard/LandingCard.js"
2019-03-19T11:03:22.061Z Created lambda for page: "components/mapview/components/mapview/MapView.js"
2019-03-19T11:03:22.759Z Created lambda for page: "components/mapview/MapContainer.js"
2019-03-19T11:03:23.336Z Created lambda for page: "components/navbar/components/burgermenu/BurgerMenu.js"
2019-03-19T11:03:23.772Z Created lambda for page: "components/navbar/NavBar.js"
2019-03-19T11:03:24.416Z Created lambda for page: "components/servicescard/ServicesCard.js"
2019-03-19T11:03:24.988Z Created lambda for page: "index.js"
2019-03-19T11:03:28.817Z preparing cache ...
2019-03-19T23:29:10.708Z REPORT RequestId: 2b7c115d-9d46-4eef-a2d9-4788ed22116a Duration: 130.73 ms Billed Duration: 200 ms Memory Size: 3008 MB Max Memory Used: 89 MB
最佳答案
您必须将 lambda 与以下 now.json
结合使用
{
"version": 2,
"builds": [
{ "src": "package.json", "use": "@now/next" },
{ "src": "lambda_file.js", "use": "@now/node"}
],
"routes": [
{ "src": "api_route", "dest": "lambda_file.js"}
]
}
关于reactjs - 使用 Zeit Now 进行 Next js + Express 部署时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55226631/
这个问题已经有答案了: How to modify a public field of a field of a field… As in link.next.next.next(.next*n) n
我有一个保存链接的数组。每个链接都有一个名为 next 的公共(public)字段,它可以保存另一个链接,该链接可以保存更多链接等。当我想删除东西时我可以做 array[x].next = array
文档概述了在中间件中使用“await next()”的用例,导致中间件暂停并触发下游的下一个中间件,直到所有中间件都执行完毕,此时上游级联将开始并且中间件将完整执行。如果用户想要缩短级联,那么单独写“
我今天遇到了一个用例,我试图让我的 nextjs 应用程序在 android webview 中工作,不幸的是 android 不解析以 _next 开头的路径并且我的大部分块文件都在_next/st
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 8 年前。 Improve th
next-with-apollo npm 库和 the approach shown in next.js docs 中选择的“next.js 中的 apollo-client”方法对比. next.
我尝试使用 next-auth 获取凭据身份验证,但我没有使用它的经验,无论我做什么,我都会收到以下消息:[next-auth][error][callback_credentials_jwt_err
更改语言时需要更改路线名称。例如,我有一条路线 /en/career但是当我改成捷克语时,我需要一条路线 /cs/kariera .基本上我需要本地化 URL。现在,当我在 /en/career 上时
更好/优雅的方法是什么? jQuery(this).find('title').next().next().next().eq(0).text(); //THIS WORKS 我尝试使用 jQuery
我只是对 node 感到好奇。 node.next 和 node.next。到目前为止,我们已经了解到节点有两个部分,其中存储数据和下一个节点的地址(node.next),然后是 node.next.
好的,我正在尝试单独隐藏这组信息。 这有效: $(".arrow").click(function() { $(this).next().next().slideToggle(); }); Mo
我开发了一个 Web 应用程序,它使用 Nextjs 应用程序作为前端和一个 Python (Django) API 服务器作为后端。我的大多数前端页面都有对后端服务器的 API 调用(在 Compo
如果我没有通过身份验证,我正在尝试使用NextJS中间件保护一些路由,我正在使用Next-auth进行身份验证,从文档中看,这就是MIDDLEWAR.TS文件应该是什么样子。Rn的问题是,即使当我通过
我正在使用 nextJs,需要添加对 less 和 css 的支持。我想要一个项目同时拥有 next-css 和 next-less 。但它一次接受一个。这是我正在使用的 const withCSS
我正在构建下一个项目的 typescript 。如果我将此配置文件保留为 next.config.js , 我在 tsconfig.json 收到警告说“找不到next.config.ts”。所以 t
我有一个自定义登录网址/ View /模板。我对页面使用 @login_required 装饰器(让 称为 my_page) 需要登录。试图访问 my_site.com/my_page 正确调用 my
下面的代码工作正常: class String def foo next! end end puts 'hh'.foo # hi 这个也很好用: class String d
我在我的Next.js应用程序中使用Next-auth进行身份验证。成功登录后,我立即被重定向到登录页面,表明该会话已变为未经身份验证。。相关代码片段:。_app.tsx:。Layout.tsx:。L
我想在 nextjs 中创建动态页面以匹配以下路由 users/[user]/[dashboard]。我的文件结构 pages/ users/ -[user].js // will
我直接按照官网的步骤操作: https://nextjs.org/docs/ 第一步。 npm install --save next react react-dom 步骤 2. 将脚本添加到 pac
我是一名优秀的程序员,十分优秀!