Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

项目启动后请求网页地址无响应,迫于 raw.githubusercontent.com 无法访问 #8

Open
ghost opened this issue May 23, 2020 · 2 comments

Comments

@ghost
Copy link

ghost commented May 23, 2020

前言

由于一些不可描述的原因,在不连接梯子的情况下,raw.githubusercontent.com 无法访问,这导致 starter 项目无法启动。

表现情况

执行 npm run dev 之后,提示 UnhandledPromiseRejectionWarning: Error: getaddrinfo ENOENT raw.githubusercontent.com,请求网页地址无响应

下图为部分日志信息

启动日志

网页无响应

原因分析

查看 app.js 可发现,只有 await 后的 promiseresolved,即 axios.get 后面的地址可以正常访问时,才可以 res.render 页面

image

解决方案

  • 配置 host

    151.101.76.133 raw.githubusercontent.com

  • 使用本地 mock 资源文件

    请参考 527c893

@ghost ghost changed the title 项目启动后页面无法访问,迫于 raw.githubusercontent.com 无法访问 项目启动后请求网页地址无响应,迫于 raw.githubusercontent.com 无法访问 May 23, 2020
@aturX
Copy link

aturX commented Nov 13, 2020

我把数据json重新上传了一下。 有需要的用下面这段代码直接替换 app.js 的内容。

const express = require('express')
const ejs = require('ejs')
const path = require('path')
const axios = require('axios')

const app = express()

app.use(express.static(__dirname))

app.set('views', path.join(__dirname, '/templates'));
app.set('view engine', 'ejs');

/**
 * Home Page & Post List Page
 */
app.get('/', async (req, res) => {
  const response = await axios.get('https://siasky.net/bAAtgVsQxC3pJ-7qGUq6i44zZQTCxhH2EcwImBMdZAYZNg')
  res.render('index', { ...response.data })
})

/**
 * Post Page
 */
app.get('/post/:postName', async (req, res) => {
  const response = await axios.get('https://siasky.net/TAAoMVOsCzy-3y2_rHboPaxLOR5yLjROXCOzFDhOubjuAg')
  res.render('post', { ...response.data })
})

/**
 * Archives Page
 */
app.get('/archives', async (req, res) => {
  const response = await axios.get('https://siasky.net/bADP0IxV4OVpVIToo0XeCrQXCQP039mhwEPwlsso1ds_kA')
  res.render('archives', { ...response.data })
})

/**
 * tags Page
 */
app.get('/tags', async (req, res) => {
  const response = await axios.get('https://siasky.net/NADpQiWGO9N-CiDgLq1gX1g_U0E6BhiF7pEzFudWQmpZnQ')
  res.render('tags', { ...response.data })
})

/**
 * tag Page
 */
app.get('/tag/:tagName', async (req, res) => {
  const response = await axios.get('https://siasky.net/RABxGdKatRxg9XfFPOTMlnJIhu79ypKcbFMY-7NYJsh8Nw')
  res.render('tag', { ...response.data })
})

//使用8080端口
app.listen(3001)
console.log("The server is running on 3001")


@fullstack-kingj
Copy link

我把数据JSON文件下载到项目本地,改为文件访问,可以解决掉数据访问失败或者慢的问题。改之后的项目地址:https://github.com/fullstack-kingj/gridea-theme-starter.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants