title | layout | category | updated | weight | intro |
---|---|---|---|---|---|
Camp |
2017/sheet |
JavaScript libraries |
2017-09-21 |
-1 |
[Camp](https://github.com/espadrine/sc/) is a Node.js web server framework. This guide targets Camp v17.x.
|
{: .-three-column}
{: .-prime}
{: .-file}
const Camp = require('camp')
const camp = Camp.start({ port: 1234 })
{: .-file}
<!doctype html>
<body>Hello world!</body>
Camp serves files in web/
by default.
camp.path('/search', (req, res) => {
const q = res.query.q
res.json({ results: ··· })
})
{: data-line="2"}
Also available: camp.post
, camp.get
.
const tpl = Camp.template('./templates/post.html')
camp.path('/blog/:post.html', (req, res) => {
res.template({
text: 'Hello world'
}, tpl)
})
{: data-line="1,4"}
See: Templates
camp.notFound('/*.lol', (req, res) => {
res.file('/404.html')
})
{: data-line="1"}
See: Fall through
camp.handle((req, res, next) => {
res.setHeader('X-Hello', 'world')
next()
})
{: data-line="1"}
See: Handlers
const tpl = Camp.template('/templates/post.html')
camp.path('/blog/:post.html', (req, res) => {
res.template({
text: 'Hello world'
}, tpl)
})
{: data-line="1,4,5,6"}
camp.path('blog.html')
Uses blog.html
as a template.
See: Templates
camp.ws('/path', (socket) => { ··· })
camp.wsChannels[path]
camp.wsBroadcast('/path', (req, res) => {
})
Sorry I don't completely understand this yet, but check it out in their docs.
See: WebSocket