@dimerapp/http-server v2.0.3
Dimer Http server
Serve dimer datastore over HTTP server
This module can be used to serve Dimer datastore JSON files over HTTP server.
Installation
npm i @dimerapp/http-server
# yarn
yarn add @dimerapp/http-serverUsage
Http server needs a callback, which is used as a middleware and must attach basePath property to req object.
The basePath is the path where .json files for a website project are stored.
const httpServer = require('@dimerapp/http-server')
const { router, createServer } = httpServer({
cors: {}, // https://github.com/expressjs/cors#readme
NODE_ENV: 'development'
})
// This middleware is required and must set the basePath
router.use((req, res, next) => {
req.basePath = join(__dirname, 'api')
// optionally
req.distPath = 'dist'
next()
})
createServer().listen(5000)API
/config.json
Returns the config for the project.
| Status code | Response |
|---|---|
| 200 | The response will be an object of config |
/versions.json
Returns versions for the project
| Status code | Response |
|---|---|
| 200 | The response will be an array of versions. |
/version/:no.json
Returns the content tree for a given version.
You can also use the keyword default instead of defining the version number.
| Status code | Response |
|---|---|
| 200 | An array of docs nested under categories. |
| 404 | If version doesn't exists. |
/version/:no/:permalink.json
Returns doc content for a given permalink on a given version.
You can also use the keyword default instead of defining the version number.
| Status code | Response |
|---|---|
| 200 | An object containing the doc meta data and actual content in JSON format. |
| 404 | If doc doesn't exists. |
| 301 | If permalink resolves as a redirect for a given doc. The returned response will have the actual permalink. |
/search/:no.json
Search for content for a given version.
You can also use the keyword default instead of defining the version number.
| Status code | Response |
|---|---|
| 200 | An array of docs for the matched result ordered by their score |
Change log
The change log can be found in the CHANGELOG.md file.
Contributing
Everyone is welcome to contribute. Please take a moment to review the contributing guidelines.
Authors & License
thetutlage and contributors.
MIT License, see the included MIT file.