尝试访问Netlify上部署的站点时“找不到页面”

时间:2018-06-08 02:00:44

标签: r hugo blogdown netlify

我正在运行静态Repository: https://github.com/taraskaduk/taraskaduk Build command: hugo Publish directory: public Production branch: master Branch deploys: Deploy only the production branch and its deploy previews Public deploy logs: Logs are public 网站并将其部署在Netlify上。我在GitHub上发送文件,Hugo构建网站,Netlify部署它。

Netlify报告网站是实时的(部署日志包含在底部),但是当我尝试查看我的网站时,我看到的只是Netlify错误消息:

  

找不到页面

     

您似乎已经关注了断开的链接或输入了此网站上不存在的网址。

     

←返回我们的网站

可能是什么原因?

我的GitHub回购:https://github.com/taraskaduk/taraskaduk

网站所在的网址:https://taraskaduk.com/

我的部署设置:

HUGO_VERSION 0.37.1

雨果版(我试过不同的版本)

9:56:27 PM: Build ready to start 9:56:28 PM: Fetching cached dependencies 9:56:29 PM: Starting to download cache of 172.4MB 9:56:30 PM: Finished downloading cache in 1.74774892s 9:56:30 PM: Starting to extract cache 9:56:33 PM: Finished extracting cache in 2.59393707s 9:56:33 PM: Finished fetching cache in 4.428746301s 9:56:33 PM: Starting to prepare the repo for build 9:56:33 PM: Preparing Git Reference refs/heads/master 9:56:34 PM: Starting build script 9:56:34 PM: Installing dependencies 9:56:35 PM: Started restoring cached node version 9:56:37 PM: Finished restoring cached node version 9:56:37 PM: v8.11.2 is already installed. 9:56:38 PM: Now using node v8.11.2 (npm v5.6.0) 9:56:38 PM: Attempting ruby version 2.3.6, read from environment 9:56:39 PM: Using ruby version 2.3.6 9:56:39 PM: Using PHP version 5.6 9:56:39 PM: Installing Hugo 0.37.1 9:56:39 PM: Started restoring cached go cache 9:56:39 PM: Finished restoring cached go cache 9:56:39 PM: unset GOOS; 9:56:39 PM: unset GOARCH; 9:56:39 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.10.linux.amd64'; 9:56:39 PM: export PATH="/opt/buildhome/.gimme/versions/go1.10.linux.amd64/bin:${PATH}"; 9:56:39 PM: go version >&2; 9:56:39 PM: export GIMME_ENV='/opt/buildhome/.gimme/env/go1.10.linux.amd64.env'; 9:56:39 PM: go version go1.10 linux/amd64 9:56:39 PM: Installing missing commands 9:56:40 PM: Verify run directory 9:56:40 PM: Executing user command: hugo 9:56:40 PM: Building sites … 9:56:40 PM: 9:56:40 PM: | EN 9:56:40 PM: +------------------+----+ 9:56:40 PM: Pages | 6 9:56:40 PM: Paginator pages | 0 9:56:40 PM: Non-page files | 49 9:56:40 PM: Static files | 39 9:56:40 PM: Processed images | 0 9:56:40 PM: Aliases | 4 9:56:40 PM: Sitemaps | 1 9:56:40 PM: Cleaned | 0 9:56:40 PM: Total in 522 ms 9:56:40 PM: Caching artifacts 9:56:40 PM: Started saving pip cache 9:56:40 PM: Finished saving pip cache 9:56:40 PM: Started saving emacs cask dependencies 9:56:40 PM: Finished saving emacs cask dependencies 9:56:40 PM: Started saving maven dependencies 9:56:40 PM: Finished saving maven dependencies 9:56:40 PM: Started saving boot dependencies 9:56:40 PM: Finished saving boot dependencies 9:56:40 PM: Started saving go dependencies 9:56:40 PM: Finished saving go dependencies 9:56:40 PM: Build script success 9:56:40 PM: Starting to deploy site from 'public' 9:56:41 PM: Starting post processing 9:56:41 PM: Post processing done 9:56:41 PM: Site is live

我的最新部署日志:

    var mongoose        = require('../DBSchema/SchemaMapper');
    var UserSchema      = mongoose.model('User');

    var UserController = function(){
        this.insert = (data) => {
            return new Promise((resolve, reject) => {
                var user = new UserSchema({
                    userName: data.userName,
                    password: data.password
                });
                user.save().then(() => {
                    resolve({status: 200, message: "Added new user"});
                }).catch(err => {
                    reject({status: 500, message: "Error:- "+err});
                })
            })

        }

        this.update = (id, data) => {
            return new Promise((resolve, reject) => {
                UserSchema.update({_id: id}, data).then(() => {
                    resolve({status: 200, message: "update user"});
                }).catch(err => {
                    reject({status: 500, message: "Error:- " + err});
                })
            })
        }

        this.searchAll = () => {
            return new Promise((resolve, reject) => {
                UserSchema.find().exec().then((data) => {
                    resolve({status: 200, data: data});
                }).catch(err => {
                    reject({status: 500, message: "Error:- " + err});
                })
            })
        }

        this.search = (id) => {
            return new Promise((resolve, reject) => {
                UserSchema.find({_id:id}).exec().then(user => {
                    resolve({status: 200, data: user});
                }).catch(err => {
                    reject({status: 500, message: "Error:- " + err});
                })
            })
        }

        this.delete = (id) => {
            return new Promise((resolve, reject) => {
                UserSchema.remove({_id:id}).then(() => {
                    resolve({status: 200, message: "remove user"});
                }).catch(err => {
                    reject({status: 500, message:"Error:- " + err});
                })
            })
        }
    }

    module.exports = new UserController();

    ///Route
    var express     = require('express');
    var router      = express.Router();
    var Controller  = require('./User.Controller');



    router.post('/', (req, res) => {
        Controller.insert(req.body).then(data => {
            res.status(data.status).send({message: data.message});
        }).catch(err => {
            res.status(err.status).send({message: err.message});
        })
    });

    router.put('/:id', (req, res) => {
        Controller.update(req.params.id, req.body).then(data => {
            res.status(data.status).send({message: data.message});
        }).catch(err => {
            res.status(err.status).send({message: err.message});
        })
    });

    router.get('/', (req, res) => {
        Controller.searchAll().then(data => {
            res.status(data.status).send({data: data.data});
        }).catch(err => {
            res.status(err.status).send({message: err.message});
        });
    });

    router.get('/:id', (req, res) => {
        Controller.search(req.params.id).then(data => {
            res.status(data.status).send({data: data.data});
        }).catch(err => {
            res.status(err.status).send({message: err.message});
        });
    });

    router.delete('/:id', (req, res) => {
        Controller.delete(req.params.id).then(data => {
            res.status(data.status).send({message: data.message});
        }).catch(err => {
            res.status(err.status).send({message: err.message});
        })
    })

    module.exports = router;

//db`enter code here`schema

var mongoose = require('mongoose');
const Schema = mongoose.Schema;

var Supplier =new Schema({

    itemId:{
        type:String,
        required:true
    },
    brand:{
        type:String,
        required:true
    },
    pno:{
        type:String,
        required:true
    },   
    email:{
        type:String,
        required:true
    }    

});

mongoose.model('Inventory',Inventory);
mongoose.model('Supplier',Supplier);

mongoose.connect('mongodb://127.0.0.1:27017/LAB', function (err) {
    if (err) {
        console.log(err);
        process.exit(-1);
    }
    console.log("Connected to the db");
});
module.exports = mongoose;

9 个答案:

答案 0 :(得分:13)

免责声明:我在支持团队@ Netlify

工作

我们总是允许就这些事情与Netlify支持联系,尽管我们只能真正帮助您调试我们的构建过程与本地的不同,而不是调试源代码。让我扩展评论者提出的一些最佳实践,并提供一些建议,以帮助您进一步调试,这是非显而易见的。

首先,正如所建议的那样(感谢@aosmith!)BaseURL应设置为/ - 这是最佳做法,并允许您的网站在本地(http://localhost)工作,但也可以在Netlify上工作 - 通过http,https ,deploy previews,最后是其他托管服务提供商,代理服务器等等,只需这样做:)

其次,您不仅可以在_redirects文件中重定向,还可以重定向netlify.toml,但我也不认为这是问题所在。

当您在主网址上获得404时,表示您没有/index.html。造成这种情况的根本原因是,我无法分辨(虽然我可以说当你的主题缺失并且可能无法产生你期待的内容时,hugo并不喜欢它)。有两种很好的方法可以找出为什么我们的构建版本不会在您的发布文件夹中生成index.html(public,在您的情况下和默认的hugo配置中),但是:

  1. 您可以从我的屏幕截图中显示的部署日志页面下载任何成功部署的副本,并查看"我们最终的结果"。这里的典型问题是我们什么都没有(你的构建没有公开/或者你最终没有index.html - 所以我们正确显示没有路径的404)

  2. 您可以按照调试说明在本地运行我们的构建映像:https://github.com/netlify/build-image#testing-locally。构建之后,您仍然在构建shell中,可以查看发布目录中的内容。

  3. screenshot indicating deploy download location

答案 1 :(得分:5)

如果直接浏览到特定路径时看到“未找到”错误,例如https://yourdomain.com/something,这可能会有所帮助(ReactJS):

在您的public文件夹(包含index.html的文件夹)中,创建一个没有扩展名的文件_redirects。然后,在其中键入以下内容:

/* /index.html 200

现在保存,提交,推送和发布。 :)

“未找到”的原因是,当使用路由器(例如:React Router)时,它会处理所有路由,但是当您直接转到端点时,netlify必须知道将您重定向到何处。这就是我们在_redirects文件中指定的内容。

答案 2 :(得分:2)

看起来我修好了。 我创建了一个带有示例站点的新repo,并开始用我的部件替换部分示例站点以查看它何时中断。

因此,为了让网站再次正常部署,必须排除config.toml的这一部分:

[permalinks]
    post = "/:year/:month/:day/:slug/" 

我不确定为什么 - 它总是在那里,当我在本地构建我的网站时它起作用,但是当我添加public文件夹后我不想工作.gitignore让hugo建立我的网站。

任何想法为什么会这样?

答案 3 :(得分:1)

如果您使用的是Angular 8,则需要通过读取angular.json构建outputPath来提供发布目录值,如果您使用的是旧版本,则应该为{{ 1}},即您可以从.angular-cli.json中读取的dist/{project-name}的值。

答案 4 :(得分:1)

Angular 8和现在的Angular 9在dist / {项目名称}中发布,即要键入的文件夹名称,而不仅仅是像以前版本中的dist。如果仅指定dist,它将在错误的目录中查找index.html,结果将是“找不到页面”。

答案 5 :(得分:0)

解决了这个问题。我的解决方案是在 netlify.toml 文件中设置 publish 声明的正确构建路径。新的netlify自动化部署过程使用此文件从存储库中部署项目。

答案 6 :(得分:0)

将您的主HTML文件命名为index.html,而不是其他任何名称。

答案 7 :(得分:0)

对于Angular,我遇到了这个问题,并且发现以下工作可行:

touch src/_redirects

This file will contain the rule below. It indicates that all requests to the server should be redirected to index.html. We also add a HTTP status code option at the end to indicate that these redirects should return a 200 status. By default, a 301 status is returned.

/*  /index.html 200

The last thing we have to do is add the below option in our angular.json und er projects > {your_project_name} > architect > options > assets. Include it in the assets array:

{
  "glob": "_redirects",
  "input": "src",
  "output": "/"
}

来自https://www.smashingmagazine.com/2020/10/angular-feedback-netlify-forms-edge/

答案 8 :(得分:0)

enter image description here

我确保“发布目录”和构建文件夹的名称相同。然后我推送了@Adwaith 上面建议的更改。非常感谢@Adwaith,您的意见是我的救星。