gridea-theme-starter icon indicating copy to clipboard operation
gridea-theme-starter copied to clipboard

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

Open ghost opened this issue 5 years ago • 2 comments

前言

由于一些不可描述的原因,在不连接梯子的情况下,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 avatar May 23 '20 10:05 ghost

我把数据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")


aturX avatar Nov 13 '20 07:11 aturX

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

fullstack-kingj avatar Nov 23 '20 00:11 fullstack-kingj