Skip to content

Commit 7252058

Browse files
committed
Initial commit, choo working
0 parents  commit 7252058

19 files changed

+8740
-0
lines changed

.gitignore

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
2+
# Created by https://www.gitignore.io/api/node,linux,macos,windows
3+
4+
### Linux ###
5+
*~
6+
7+
# temporary files which can be created if a process still has a handle open of a deleted file
8+
.fuse_hidden*
9+
10+
# KDE directory preferences
11+
.directory
12+
13+
# Linux trash folder which might appear on any partition or disk
14+
.Trash-*
15+
16+
# .nfs files are created when an open file is removed but is still being accessed
17+
.nfs*
18+
19+
### macOS ###
20+
*.DS_Store
21+
.AppleDouble
22+
.LSOverride
23+
24+
# Icon must end with two \r
25+
Icon
26+
27+
# Thumbnails
28+
._*
29+
30+
# Files that might appear in the root of a volume
31+
.DocumentRevisions-V100
32+
.fseventsd
33+
.Spotlight-V100
34+
.TemporaryItems
35+
.Trashes
36+
.VolumeIcon.icns
37+
.com.apple.timemachine.donotpresent
38+
39+
# Directories potentially created on remote AFP share
40+
.AppleDB
41+
.AppleDesktop
42+
Network Trash Folder
43+
Temporary Items
44+
.apdisk
45+
46+
### Node ###
47+
# Logs
48+
logs
49+
*.log
50+
npm-debug.log*
51+
yarn-debug.log*
52+
yarn-error.log*
53+
54+
# Runtime data
55+
pids
56+
*.pid
57+
*.seed
58+
*.pid.lock
59+
60+
# Directory for instrumented libs generated by jscoverage/JSCover
61+
lib-cov
62+
63+
# Coverage directory used by tools like istanbul
64+
coverage
65+
66+
# nyc test coverage
67+
.nyc_output
68+
69+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
70+
.grunt
71+
72+
# Bower dependency directory (https://bower.io/)
73+
bower_components
74+
75+
# node-waf configuration
76+
.lock-wscript
77+
78+
# Compiled binary addons (http://nodejs.org/api/addons.html)
79+
build/Release
80+
81+
# Dependency directories
82+
node_modules/
83+
jspm_packages/
84+
85+
# Typescript v1 declaration files
86+
typings/
87+
88+
# Optional npm cache directory
89+
.npm
90+
91+
# Optional eslint cache
92+
.eslintcache
93+
94+
# Optional REPL history
95+
.node_repl_history
96+
97+
# Output of 'npm pack'
98+
*.tgz
99+
100+
# Yarn Integrity file
101+
.yarn-integrity
102+
103+
# dotenv environment variables file
104+
.env
105+
106+
### Windows ###
107+
# Windows thumbnail cache files
108+
Thumbs.db
109+
ehthumbs.db
110+
ehthumbs_vista.db
111+
112+
# Folder config file
113+
Desktop.ini
114+
115+
# Recycle Bin used on file shares
116+
$RECYCLE.BIN/
117+
118+
# Windows Installer files
119+
*.cab
120+
*.msi
121+
*.msm
122+
*.msp
123+
124+
# Windows shortcuts
125+
*.lnk
126+
127+
128+
# End of https://www.gitignore.io/api/node,linux,macos,windows

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# `choo-express-ssr`
2+
3+
A simple boilerplate for [Choo](https://github.com/choojs/choo)
4+
5+
Heavily inspired by [Firefox Send](https://github.com/mozilla/send)
6+
7+
## Install
8+
9+
After `git clone`
10+
11+
```bash
12+
npm install
13+
npm start
14+
```
15+
16+
## License
17+
18+
[MIT](https://poyu.mit-license.org)

app/main.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
h1 {
2+
color: red;
3+
}

app/main.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import app from './routes'
2+
3+
app.mount('body')

app/pages/about.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const html = require('choo/html')
2+
3+
module.exports = function(state, emit) {
4+
return html`
5+
<main>
6+
<h1>About Page</h1>
7+
<p>This is the about page</p>
8+
<a href="/">Home</a>
9+
<p>URL: ${state.url}</p>
10+
</main>
11+
`
12+
}

app/pages/home.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const html = require('choo/html')
2+
3+
module.exports = function(state, emitter) {
4+
return html`
5+
<main>
6+
<h1>Home Page</h1>
7+
<p>Hello World</p>
8+
<a href="/about">About</a>
9+
<p>URL: ${state.url}</p>
10+
</main>
11+
`
12+
}
13+

app/routes/index.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const choo = require('choo')
2+
const html = require('choo/html')
3+
4+
const app = choo()
5+
6+
function body(template) {
7+
return function(state, emit) {
8+
const body = html`
9+
<body>
10+
${template(state, emit)}
11+
</body>
12+
`
13+
if (state.layout) {
14+
return state.layout(state, body)
15+
}
16+
return body
17+
}
18+
}
19+
20+
app.route('/', body(require('../pages/home')))
21+
app.route('/about', body(require('../pages/about')))
22+
23+
module.exports = app

build/gen_asset_map.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
4+
function kv(f) {
5+
return `"${f}": require('../assets/${f}')`
6+
}
7+
8+
module.exports = function() {
9+
const files = fs.readdirSync(path.join(__dirname, '..', 'assets'))
10+
const code = `module.exports = {
11+
"package.json": require('../package.json'),
12+
${files.map(kv).join(',\n')}
13+
};`
14+
15+
return {
16+
code,
17+
dependencies: files.map(f => require.resolve('../assets/' + f)),
18+
cacheable: true
19+
}
20+
}

common/assets.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const genmap = require('../build/gen_asset_map')
2+
const isServer = typeof genmap === 'function'
3+
const prefix = isServer ? '/' : ''
4+
let manifest = {}
5+
try {
6+
manifest = require('../dist/manifest.json')
7+
} catch (e) {
8+
// use middleware
9+
}
10+
11+
const assets = isServer ? manifest : genmap
12+
13+
function getAsset(name) {
14+
return prefix + assets[name]
15+
}
16+
17+
const instance = {
18+
get: getAsset,
19+
setMiddleware: function(middleware) {
20+
if (middleware) {
21+
instance.get = function getAssetWithMiddleware(name) {
22+
const f = middleware.fileSystem.readFileSync(
23+
middleware.getFilenameFromUrl('/manifest.json')
24+
)
25+
return prefix + JSON.parse(f)[name]
26+
}
27+
}
28+
}
29+
}
30+
31+
module.exports = instance

0 commit comments

Comments
 (0)