@dmail/server
v2.10.0
Published
[](https://www.npmjs.com/package/@dmail/server) [](http://travis-ci.com/dmail/server) [ => {
return {
status: 200,
headers: {
"content-type": "text/plain",
},
body: "Hello world",
}
},
})If you want to know more about startServer, there is a dedicated page documenting it.
— see startServer documentation
serveFile example
The following code starts a server listening to http://127.0.0.1:8080 serving files of the current directory.
import { startServer, serveFile } from "@dmail/server"
startServer({
protocol: "http",
ip: "127.0.0.1",
port: 8080,
requestToResponse: ({ ressource, method, headers }) =>
serveFile(`${__dirname}${ressource}`, {
method,
headers,
}),
})If you want to know more about serveFile, there is a dedicated page documenting it.
— see serveFile documentation
firstService example
Let's make a generateResponse function with the following behaviour:
- returns
204 no contentresponse for/ - returns
200 okresponse for/whatever
import { firstService } from "@dmail/server"
const generateResponse = (request) => {
return firstService(
() => {
if (ressource !== "/") return null
return { status: 204 }
},
() => {
if (ressource !== "/whatever") return null
return { status: 200 }
},
)
}If you want to know more about firstService, there is a dedicated page documenting it.
— see firstService documentation
Installation
npm install @dmail/[email protected]