Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/b2d1/news-ssr
https://github.com/b2d1/news-ssr
Last synced: 21 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/b2d1/news-ssr
- Owner: B2D1
- License: mit
- Created: 2019-09-11T13:14:06.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-09-19T12:20:40.000Z (over 5 years ago)
- Last Synced: 2024-11-06T00:11:58.590Z (2 months ago)
- Language: JavaScript
- Size: 4.26 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# news-ssr
## 运行
```js
cd news-ssr
# 开启后端服务 8080
node server.js
# 开发模式 3000
npm run dev
# 打包
npm run build
# 运行打包文件 3000
npm run start
# 导出静态资源
npm run export
# 开启静态服务,监听 3000 端口,需安装 serve 包
cd out && serve -p 3000
```## 坑点
- 当修改了 `Schema` 配置,需要删除数据库并重启
- `bodyParser` 必须放在 `router` 之前
- `Mongoose` 查找不到单个对象时,返回 `null`
- 使用 `fetch` 时,当后端返回 `204 No Content`,无法调用 `json()`,且返回的文本是**只读**的,可以自己去手动调用 `JSON.parse()`
- `Mongoose` 基于回调函数的形式,可以用 `Promise.all()` 来简化解决多个修改操作
- 一对多,多对一关系,使用 `ref,Schema.Types.ObjectId,populate`