Basic API server made with hapi and MongoDB.
npm install @electricg/hapi-mongodb-server
A complete example is available in the example
directory.
const api = require("@electricg/hapi-mongodb-server");
const port = 8083;
const host = "127.0.0.1";
const mongodbUrl = "mongodb://localhost:27017/test";
const mongodbOptions = {
autoReconnect: true
};
const allowedOrigins = ["*"];
const routes = [
{
method: "GET",
path: "/",
handler: handler: () => {
return { name: "test", version: "1.0.0" };
}
}
];
const settings = {
db: {
uri: mongodbUrl,
options: mongodbOptions
},
server: {
port: port,
host: host,
origin: allowedOrigins,
routes: routes
}
};
api.start(settings);