Skip to content

Commit e599b85

Browse files
committed
feat: optimize index route
1 parent 604a6a4 commit e599b85

File tree

6 files changed

+29
-26
lines changed

6 files changed

+29
-26
lines changed

public/favicon.ico

1.12 KB
Binary file not shown.

server/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ function getCacheKey(req) {
1616
async function cacheRender(req, res) {
1717
const key = getCacheKey(req);
1818
// reder /list to /
19-
const reqPath = req.path === '/list' ? '/' : req.path;
19+
// const reqPath = req.path === '/list' ? '/' : req.path;
20+
const reqPath = req.path;
2021
if (Cache.has(key)) {
2122
res.setHeader('X-Cache', 'HIT');
2223
res.send(Cache.get(key));
@@ -44,7 +45,7 @@ async function startServer() {
4445
app.setAssetPrefix(process.env.STATIC_PATH);
4546
server.use(Express.static(join(__dirname, '../public/static')));
4647

47-
server.get('/list', async (req, res) => {
48+
server.get('/', async (req, res) => {
4849
return cacheRender(req, res);
4950
});
5051

serverless.yml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
org: serverless-cnode
22
app: serverless-cnode
33
stage: dev
4-
component: nextjs
4+
component: nextjs@dev
55
name: serverless-cnode
66

77
inputs:
88
src:
9-
src: ./
9+
dist: ./
10+
hook: npm run build
1011
exclude:
1112
- .env
1213
region: ap-guangzhou
@@ -17,22 +18,22 @@ inputs:
1718
- http
1819
- https
1920
environment: release
20-
enableCORS: true # 允许跨域
21-
customDomains: # 自定义域名绑定
22-
- domain: cnode.yuga.chat # 待绑定的自定义的域名
23-
certificateId: eGesL28k # 待绑定自定义域名的证书唯一 ID
24-
# 自定义路径映射的路径。使用自定义映射时,可一次仅映射一个 path 到一个环境,也可映射多个 path 到多个环境。并且一旦使用自定义映射,原本的默认映射规则不再生效,只有自定义映射路径生效。
21+
enableCORS: true
22+
customDomains:
23+
- domain: cnode.yuga.chat
24+
certificateId: eGesL28k
2525
pathMappingSet:
2626
- path: /
2727
environment: release
28-
# 绑定自定义域名的协议类型,默认与服务的前端协议一致。
2928
protocols:
3029
- http
3130
- https
32-
staticCdn:
33-
cosConf:
34-
bucket: serverless-cnode
35-
cdnConf:
36-
domain: static.cnode.yuga.chat
37-
https:
38-
certId: eGkM75xv
31+
staticCdn:
32+
cosConf:
33+
bucket: serverless-cnode
34+
cdnConf:
35+
# after you deploy CDN once, just set onlyRefresh to true for refresh CDN cache
36+
onlyRefresh: true
37+
domain: static.cnode.yuga.chat
38+
https:
39+
certId: eGkM75xv

src/components/layout/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default class Layout extends Component<{
2121
content='initial-scale=1.0, width=device-width'
2222
/>
2323
{title ? <title>{title}</title> : ''}
24+
<link rel='icon' href={`${process.env.STATIC_URL}/favicon.ico`} />
2425
<script dangerouslySetInnerHTML={{ __html: staticMarkup }}></script>
2526
</Head>
2627
{children}

src/components/link/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { View } from '@ui';
22
import React, { Component } from 'react';
3-
import Router, { withRouter } from 'next/router';
3+
import { withRouter } from 'next/router';
44

55
import * as utils from '@libs/utils';
66

@@ -28,9 +28,9 @@ class Link extends Component<IProps, PageState> {
2828

2929
goTo = ({ url, params }) => {
3030
const href = url + (params ? '?' + utils.param(params) : '');
31-
Router.push(href);
32-
// window.location.href = href;
33-
// return false;
31+
// Router.push(href, as);
32+
window.location.href = href;
33+
return false;
3434
};
3535
render() {
3636
const { className, style, to, children, ...rest } = this.props;

src/components/menu/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,27 @@ class NvMenu extends Component<IProps, {}> {
2525
<View className={styles['list-ul']}>
2626
<Link
2727
className={`icon-quanbu iconfont ${styles.item}`}
28-
to={{ url: '/list?tab=all' }}>
28+
to={{ url: '/', params: { tab: 'all' } }}>
2929
全部
3030
</Link>
3131
<Link
3232
className={`icon-hao iconfont ${styles.item}`}
33-
to={{ url: '/list?tab=good' }}>
33+
to={{ url: '/', params: { tab: 'good' } }}>
3434
精华
3535
</Link>
3636
<Link
3737
className={`icon-fenxiang iconfont ${styles.item}`}
38-
to={{ url: '/list?tab=share' }}>
38+
to={{ url: '/', params: { tab: 'share' } }}>
3939
分享
4040
</Link>
4141
<Link
4242
className={`icon-wenda iconfont ${styles.item}`}
43-
to={{ url: '/list?tab=ask' }}>
43+
to={{ url: '/', params: { tab: 'ask' } }}>
4444
问答
4545
</Link>
4646
<Link
4747
className={`icon-zhaopin iconfont ${styles.item}`}
48-
to={{ url: '/list?tab=job' }}>
48+
to={{ url: '/', params: { tab: 'job' } }}>
4949
招聘
5050
</Link>
5151
<Link

0 commit comments

Comments
 (0)