Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 1e454f4

Browse files
committed
clean up
1 parent eff68cb commit 1e454f4

File tree

2 files changed

+27
-46
lines changed

2 files changed

+27
-46
lines changed

next.config.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const { ANALYZE } = process.env
77
// https://github.com/zeit/next.js/blob/canary/examples/with-static-export/next.config.js
88

99
module.exports = {
10-
useFileSystemPublicRoutes: true,
10+
// useFileSystemPublicRoutes: false,
11+
// smartSlashes: false,
1112
exportPathMap: () => {
1213
return {
1314
'/': { page: '/' },
@@ -26,11 +27,13 @@ module.exports = {
2627
// query: { main: 'communities', sub: '' },
2728
},
2829

29-
// '/racket': {
30-
// page: '/',
31-
// query: { main: 'racket', sub: '' },
32-
// asPath: '/communities/posts',
33-
// },
30+
'/racket': {
31+
page: '/',
32+
},
33+
'/racket/posts': {
34+
page: '/',
35+
},
36+
3437
/* '/racket/tags': { */
3538
/* page: '/', */
3639
// asPath: '/communities/posts',

server.js

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const dev = process.env.NODE_ENV !== 'production'
2-
// const goal = process.env.GOAL
32

43
const { createServer } = require('http')
54
const { parse } = require('url')
@@ -13,6 +12,7 @@ const glob = require('glob')
1312
const app = next({ dev })
1413
const handle = app.getRequestHandler()
1514
const route = pathMatch()
15+
const SERVE_PORT = 3001
1616

1717
// const moduleAlias = require('module-alias')
1818
// For the development version, we'll use React.
@@ -24,7 +24,6 @@ const route = pathMatch()
2424
}
2525
*/
2626

27-
// const langMatch = route('/lang/:name')
2827
mobxReact.useStaticRendering(true)
2928

3029
const supportLanguages = glob
@@ -48,65 +47,44 @@ const getMessages = locale => {
4847
return messageCache.get(locale)
4948
}
5049

51-
// communities view for root
52-
const communitiesQuery = route('/communities')
53-
const communitiesSubQuery = route('/communities/:sub')
54-
// users view for root
55-
const usersQuery = route('/users')
56-
const usersSubQuery = route('/users/:sub')
57-
// const communityQuery = route('/:main')
58-
const communityQuery = route('/:main')
59-
const communitySubQuery = route('/:main/:sub')
50+
// routes
51+
const communitiesQuery = route('/communities/:sub?')
52+
const usersQuery = route('/users/:sub?')
6053
const localeQuery = route('/locale/:lang')
54+
const communityQuery = route('/:main/:sub?')
6155

6256
app.prepare().then(() => {
6357
createServer((req, res) => {
64-
const { pathname } = parse(req.url)
65-
/* console.log('---------> server parse(req.url): ', parse(req.url)) */
66-
// const homeMatch = homeQuery(pathname)
67-
/* const communitiesMatch = communitiesQuery(pathname) */
68-
/* const communitiesSubMatch = communitiesSubQuery(pathname) */
69-
/* const usersMatch = usersQuery(pathname) */
70-
/* const usersSubMatch = usersSubQuery(pathname) */
71-
/* const localeMatch = localeQuery(pathname) */
58+
/*
59+
req.url = req.url.replace(/\/$/, '')
60+
if (req.url === '') {
61+
req.url = '/'
62+
}
63+
handle(req, res)
64+
*/
7265

73-
const communityMatch = communityQuery(pathname)
74-
const communitySubMatch = communitySubQuery(pathname)
66+
const { pathname } = parse(req.url)
7567

7668
const accept = accepts(req)
7769
const locale = accept.language(supportLanguages) // 'zh'
7870

7971
if (localeQuery(pathname)) {
8072
res.setHeader('Content-Type', 'application/json;charset=utf-8')
8173
return res.end(JSON.stringify(getMessages(localeQuery(pathname).lang)))
82-
} else if (communitiesQuery(pathname) || communitiesSubQuery(pathname)) {
74+
} else if (communitiesQuery(pathname)) {
8375
return app.render(req, res, '/communities')
84-
} else if (usersQuery(pathname) || usersSubQuery(pathname)) {
76+
} else if (usersQuery(pathname)) {
8577
return app.render(req, res, '/users')
86-
} else if (communityMatch) {
87-
return app.render(req, res, '/', communityMatch)
88-
} else if (communitySubMatch) {
89-
return app.render(req, res, '/', communitySubMatch)
78+
} else if (communityQuery(pathname)) {
79+
return app.render(req, res, '/')
9080
}
91-
/*
92-
} else if (communityMatch) {
93-
return app.render(req, res, '/', communityMatch)
94-
} else if (communitySubMatch) {
95-
return app.render(req, res, '/', communitySubMatch)
96-
}
97-
*/
9881

99-
/*
100-
if (homeMatch) {
101-
return app.render(req, res, '/', homeMatch)
102-
}
103-
*/
10482
// now index page go this way
10583
req.locale = locale
10684
req.messages = getMessages(locale)
10785

10886
return handle(req, res)
109-
}).listen(3001, err => {
87+
}).listen(SERVE_PORT, err => {
11088
if (err) throw err
11189
console.log('> Ready on http://localhost:3001')
11290
})

0 commit comments

Comments
 (0)