2.0.3 • Published 6 years ago

@dimerapp/http-server v2.0.3

Weekly downloads
21
License
MIT
Repository
github
Last release
6 years ago

Dimer Http server

Serve dimer datastore over HTTP server

travis-image appveyor-image npm-image

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-server

Usage

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 codeResponse
200The response will be an object of config

/versions.json

Returns versions for the project

Status codeResponse
200The 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 codeResponse
200An array of docs nested under categories.
404If 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 codeResponse
200An object containing the doc meta data and actual content in JSON format.
404If doc doesn't exists.
301If 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 codeResponse
200An 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.

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago