NOTE: These instructions require MongoDB and Node.js to be installed on your environment.
git clone https://github.com/ofuochi/node-typescript-boilerplate.git
cd node-typescript-boilerplate
git checkout -b <INSERT-BRANCH-NAME>
npm install
cp env.sample .env
npm run start
http://localhost:3000/api/v1/tenants
Run test once
npm run test
Or re-run test on every file change (watch mode)
npm run test-watch
The application exposes a few REST endpoints which requires you to pass x-tenant-id
header. First call the tenant endpoint /api/v1/tenant
to get all the available tenants. Use any of the tenant IDs as the value for x-tenant-id
HTTP
GET
/api/v1/tenants
HTTP
GET
/api/v1/tenants/:query
HTTP
GET
/api/v1/secured
(Requires a validx-auth-token
header)
You can use the following code snippet to call the secured endpoint:
fetch("http://localhost:3000/api/v1/secure", {
method: "GET",
headers: {
"Content-Type": "application/json",
"x-tenant-id": "TENANT_ID",
"x-auth-token": "SOME_VALID_CREDENTIAL"
}
})
.then(r => {
if (r.status === 200) {
r.json().then(j => console.log(j));
} else {
console.log("ERROR", r.status);
}
})
.catch(e => console.log(e));
You can use the following code snippet to call the secured endpoint with an invalid x-auth-token
header:
fetch("http://localhost:3000/api/v1/secure", {
method: "GET",
headers: {
"Content-Type": "application/json",
"x-tenant-id": "TENANT_ID",
"x-auth-token": "SOME_WRONG_CREDENTIAL"
}
})
.then(r => {
if (r.status === 200) {
r.json().then(j => console.log(j));
} else {
console.log("ERROR", r.status);
}
})
.catch(e => console.log(e));