我的 Nuxt 项目中有一个简单的表单 - 托管在 Netlify 上并使用 Netlify Forms 功能 - 此处的文档https://www.netlify.com/docs/form-handling/
\n\n <form\n action="/confirm" name="request" method="post" data-netlify="true" netlify-honeypot="bot-field"\n >\n <p class="hidden">\n <label>Don\xe2\x80\x99t fill this out if you\'re human: <input name="bot-field" ></label>\n </p>\n <v-text-field\n label="Name"\n name="name"\n />\n ...\n <v-btn\n :disabled="!valid"\n type="submit"\n >send\n </v-btn>\n </form>\nRun Code Online (Sandbox Code Playgroud)\n\n如果我浏览到https://mddomain.com/confirm它工作正常。
\n\n如果我第一次提交表单,进入 /confirm 页面,但 Netlify 不保护数据。如果我再试一次,我会收到此错误消息:
\n\n\n\n\n未找到页面\n 您似乎访问了损坏的链接或输入了此网站上不存在的 URL。
\n\n返回我们的网站
\n
我的代码有什么问题吗?
\n我正在使用 Vue 构建一个 Web 应用程序,它将使用 Netlify Lambda 函数和 Express.js 作为服务器端(使应用程序成为“无服务器”)。现在 Netlify 可以实现这一点,我正在遵循他们的官方指南:如何使用 Netlify Functions 运行 Express.js 应用程序。我还使用Vue CLI 的 Netlify Lambda 插件将 lambda 函数集成到我的 Vue 构建过程中。
我有一个名为 的小型 lambda 函数server.js。当调用此函数时,它将从 Spotify API 获取数据。
'use strict';
const serverless = require("serverless-http");
const SpotifyWebApi = require("spotify-web-api-node");
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const router = express.Router();
router.get("/search", (req, res) => {
// function that searches for a song with the Spotify …Run Code Online (Sandbox Code Playgroud) 我正在努力添加环境变量来为 Netlify 函数进行条件切换。当我运行时,CONTEXT=development netlify dev我陷入了无限循环,并且 Lambda 服务器不断切换端口。
yarn develop\nyarn run v1.12.3\n$ CONTEXT=development netlify dev\n\xe2\x97\x88 Netlify Dev \xe2\x97\x88\n\xe2\x97\x88 Injected build setting env var: GATSBY_DEV_GITHUB_CLIENT_ID\n\xe2\x97\x88 Injected build setting env var: GATSBY_DEV_GITHUB_CLIENT_SECRET\n\xe2\x97\x88 Injected build setting env var: GATSBY_DEV_HOST_URL\n\xe2\x97\x88 Injected build setting env var: GATSBY_FUNCTION_PASSWORD\n\xe2\x97\x88 Injected build setting env var: GATSBY_GITHUB_CLIENT_ID\n\xe2\x97\x88 Injected build setting env var: GATSBY_GITHUB_CLIENT_SECRET\n\xe2\x97\x88 Injected build setting env var: GATSBY_HOST_URL\n\xe2\x97\x88 Injected build setting env var: GATSBY_DEV_FUNCTION_PASSWORD\n\xe2\x97\x88 Starting Netlify Dev with gatsby\nWaiting for …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试找出为什么我的网站图标没有显示。它在我的本地主机上运行良好,但是当我将其上传到 Netlify 时,它没有显示。
\n\n\n\n\n\n我正在使用 React,然后将其部署到 Netlify 服务器。不确定这是否与此有关。这是我在 public 文件夹中的 index.html 文件中放入的内容。
\n\n<link rel=\xe2\x80\x9dicon\xe2\x80\x9d href=\xe2\x80\x9d%PUBLIC_URL%/favicon.ico\xe2\x80\x9d>
正如我已经提到的,它确实可以工作并显示在我的 localhost:3000 上。关于我可能做错了什么有什么想法吗?
\n我正在开发一个百科全书类型的网站。本质上,该网站包含单词、定义、概念和博客文章的页面,我打算每周左右添加一个新页面/帖子。目前,我的每篇文章大约有 40 个 HTML 页面。之前我一直将网站的存储库发布到 Github Pages,但最近我决定通过 Netlify 托管我的网站。到目前为止,我很喜欢 Netlify 的功能,它很好地改进了我的开发过程。
但是,我的网站仍然是静态的。需要明确的是,我没有使用静态站点生成器(例如 Next.js 或 Jekyll)创建站点的文件。我希望该项目成为硬编码的实践。当前目录中唯一的文件是 HTML、CSS 和 JS 文件(以及 git 属性以及图标和字体等内容) 我已经浏览了 Netlify 的 Web 应用程序和功能部分,但是,我发现没有任何内容真正符合马克,无论是因为我是 Netlify 的新用户,还是因为我在网站索引和/或后端应用程序方面不一定有太多经验。
我的问题是,如何在静态网站的主页上实现搜索栏和标题搜索功能?这将使观众在访问后能够轻松找到我的任何特定帖子。我希望搜索栏只搜索我为帖子指定的文件夹中每个 html 文件的标题(至少现在是这样)。其他问题是我应该使用哪些网络应用程序(如果有)来完成此任务,以及我是否应该考虑更改我开发和托管网站的流程以适应这些应用程序?
我在生产环境中从 Netlify 无服务器函数返回数据时遇到问题。目前,它会在 10 秒后超时,并返回状态代码 502 和以下错误消息:
{
"errorMessage": "2019-... 5f... Task timed out after 10.01 seconds"
}
Run Code Online (Sandbox Code Playgroud)
但是,在我的开发环境中,Netlify 无服务器功能可以完美运行,并响应我数据库中的数据。
我已确认 Netlify 站点上的环境变量和我的.env文件中的环境变量是相同的。我将如何调试这个问题并解决问题?
Netlify无服务器功能
const { connectDatabase, ProjectSchema } = require('../database')
const createHeaders = origin => {
// This is a comma-separated list of allowed origins, including my local
// environment and production website
const allowedOrigins = process.env.ALLOWED_ORIGINS
? process.env.ALLOWED_ORIGINS.split(',')
: []
return {
'Content-Type': 'application/json',
'Access-Control-Allow-Headers':
'Origin, X-Requested-With, Content-Type, Accept',
'Access-Control-Allow-Origin': allowedOrigins.includes(origin)
? origin
: ''
} …Run Code Online (Sandbox Code Playgroud) 我继承了别人的项目。他们正在使用 Netlify 部署一个 ReactJS 项目。我设置了这个环境变量:
在我的代码中,我放置了一个console.log(process.env);. Netlify 构建并部署网站后,我的浏览器开发人员控制台显示以下内容:
Netlify 文档指出默认NODE_ENV设置为。development我如何将我的环境设置为development?
笔记:
我也用它yarn build来构建项目。我想知道是否yarn build有规则忽略我的NODE_ENV变量并强制环境成为生产环境,以确保开发人员永远不会发布开发版本?
我在 Netlify 上使用了一个 React 应用程序 6 个月,没有出现任何问题。从 .com 更改为 .app 后,我的网站开始收到 CORS 错误消息:
从来源“ https://jovial-mccarthy-f17fcd.netlify.app ”访问“ https://newsapi.org/v2/everything?q=bitcoin&from=2020-5-27&sortBy=publishedAt&apiKey=xxx ”处的 XMLHttpRequest已被 CORS 策略阻止:请求的资源上不存在“Access-Control-Allow-Origin”标头。
当我在本地服务器上运行时,它运行良好,并且没有错误消息,但是当在 Netlify 上部署时,我收到上面的错误消息。
我已将 netlify.toml 文件添加到我的根文件夹中:
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
[[headers]]
# Define which paths this specific [[headers]] block will cover.
for = "/*"
[headers.values]
Access-Control-Allow-Origin = "*"
Run Code Online (Sandbox Code Playgroud)
但我仍然收到错误消息,并且 api 新闻数据被阻止显示在我的网站上。
我使用 axios 进行数据调用。
import axios from 'axios';
const API_URL = "https://newsapi.org/v2/everything?q=bitcoin&from=2020-5-27&sortBy=publishedAt&apiKey=1b823477c9864b7ebb4eb4e9d4148238";
//async function grabbing bitCoin data
export const getNews = async () …Run Code Online (Sandbox Code Playgroud) 从昨天开始,我遇到了一个无法修复或找不到相关信息的错误。我可以在本地构建我的网站,不会出现错误,但是当我尝试在 Netlify 中部署它时,它失败并抛出:
\n8:19:33 AM: \xe2\x80\x8b\n8:19:33 AM: \xe2\x94\x8c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x90\n8:19:33 AM: \xe2\x94\x82 Netlify Build \xe2\x94\x82\n8:19:33 AM: \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x98\n8:19:33 AM: \xe2\x80\x8b\n8:19:33 AM: \xe2\x9d\xaf Version\n8:19:33 AM: @netlify/build 2.0.20\n8:19:33 AM: \xe2\x80\x8b\n8:19:33 AM: \xe2\x9d\xaf Flags\n8:19:33 AM: deployId: 5efc2a7760231502ad0a057d\n8:19:33 AM: mode: buildbot\n8:19:33 AM: \xe2\x80\x8b\n8:19:33 AM: \xe2\x9d\xaf Current directory\n8:19:33 AM: /opt/build/repo\n8:19:33 AM: \xe2\x80\x8b\n8:19:33 AM: \xe2\x9d\xaf Config file\n8:19:33 AM: /opt/build/repo/netlify.toml\n8:19:33 AM: \xe2\x80\x8b\n8:19:33 AM: \xe2\x9d\xaf Context\n8:19:33 AM: production\n8:19:33 AM: \xe2\x80\x8b\n8:19:33 AM: \xe2\x94\x8c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x90\n8:19:33 AM: \xe2\x94\x82 Core internal error \xe2\x94\x82\n8:19:33 AM: \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x98\n8:19:33 AM: \xe2\x80\x8b\n8:19:33 AM: Error message\n8:19:33 AM: Error: Invalid version: "1"\n8:19:33 …Run Code Online (Sandbox Code Playgroud) continuous-deployment gatsby netlify netlify-cms netlify-cli
我收到以下错误
\nnpm ERR! enoent ENOENT: no such file or directory, open \'/opt/build/repo/package.json\'\nRun Code Online (Sandbox Code Playgroud)\n这是完整的构建日志:
\n2:27:28 PM: Waiting for other deploys from your team to complete\n2:27:30 PM: Build ready to start\n2:27:32 PM: build-image version: b0258b965567defc4a2d7e2f2dec2e00c8f73ad6\n2:27:32 PM: build-image tag: v3.4.1\n2:27:32 PM: buildbot version: e1f4178b0d9779ebad1b11d5b54739f82fed3c22\n2:27:32 PM: Building without cache\n2:27:32 PM: Starting to prepare the repo for build\n2:27:32 PM: No cached dependencies found. Cloning fresh repo\n2:27:32 PM: git clone https://github.com/EitharAlotoom95/Eithar-Website-\n2:27:33 PM: Preparing Git Reference refs/heads/master\n2:27:34 PM: Starting build script\n2:27:35 PM: Installing dependencies\n2:27:35 …Run Code Online (Sandbox Code Playgroud) netlify ×10
javascript ×5
html ×3
gatsby ×2
reactjs ×2
vue.js ×2
aws-lambda ×1
cors ×1
css ×1
deployment ×1
express ×1
indexing ×1
lambda ×1
netlify-cli ×1
netlify-cms ×1
nuxt.js ×1
search ×1
static-site ×1