Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
FROM node:22.17.1-alpine

RUN mkdir -p /home/app
WORKDIR /usr/local/lib/task-service

COPY . /home/app
COPY package.json package-lock.json /usr/local/lib/task-service/
RUN npm install

WORKDIR /home/app
COPY app/ .

CMD ["node", "/home/app/index.js", "--ConfigurationFile=/home/app/tasks.json"]
CMD ["node", "/usr/local/lib/task-service/index.js", "--ConfigurationFile=/etc/task-service/tasks.json"]
39 changes: 34 additions & 5 deletions Readme.md → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ This is project is meant for learning, practicing and trying out things, not for

## Requirements

- Node 18.15.0
- ~~Node 0.10.48 - Ancient, but this version runs on my NAS, which is ancient as well.~~
- Node 22.17.1

## Setup

Expand Down Expand Up @@ -44,13 +43,43 @@ This repository contains a Dockerfile to build a container with the task service

To run the container, use the following command:

docker run -p 8000:1337 task-service
In Bash

```bash
docker run \
--rm \
--detach \
--name task-service \
--publish 3000:3000 \
--volume tasks:/usr/local/lib/task-service/data \
--volume ${PWD}/tasks.json:/etc/task-service/tasks.json:ro \
--volume ${PWD}/localhost.key:/usr/local/lib/task-service/localhost.key:ro \
--volume ${PWD}/localhost.crt:/usr/local/lib/task-service/localhost.crt:ro \
task-service
```

In PowerShell

```powershell
docker run `
--rm `
--detach `
--name task-service `
--publish 3000:3000 `
--volume tasks:/usr/local/lib/task-service/data `
--volume ${PWD}/tasks.json:/etc/task-service/tasks.json:ro `
--volume ${PWD}/localhost.key:/usr/local/lib/task-service/localhost.key:ro `
--volume ${PWD}/localhost.crt:/usr/local/lib/task-service/localhost.crt:ro `
task-service
```

The container will be available on port 8000.
The container will be available on port 3000.

## Features

- Supports HTTPS
- Authentication
- Basic
- Not much more yet 😃

## Testing
Expand Down Expand Up @@ -99,5 +128,5 @@ Invoke-WebRequest "http://localhost:3000/task/99e587e6-6550-4601-9e2a-d40d2a2dce
Delete a task

```powershell
Invoke-WebRequest "http://localhost:1337/task/99e587e6-6550-4601-9e2a-d40d2a2dce7b" -Credential $credential -AllowUnencryptedAuthentication -Method Delete
Invoke-WebRequest "http://localhost:3000/task/99e587e6-6550-4601-9e2a-d40d2a2dce7b" -Credential $credential -AllowUnencryptedAuthentication -Method Delete
```
7 changes: 7 additions & 0 deletions app/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fs = require("fs");
const persistence = require("./persistence/file/task.js")

const configFileOptions = { encoding: "utf8" };

Expand All @@ -25,4 +26,10 @@ function getConfig() {
}
}
}

function setup() {
persistence.setup();
}

exports.setup = setup;
exports.getConfig = getConfig;
2 changes: 1 addition & 1 deletion app/handler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const task = require("../task/task.js");
const task = require("./task/task.js");
const { authenticate } = require("./auth/auth.js");

function postTask(req, res) {
Expand Down
5 changes: 3 additions & 2 deletions index.js → app/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"use strict";

const fs = require("fs");
const { getConfig } = require("./app/config.js");
const { app } = require("./app/app.js");
const { getConfig, setup } = require("./config.js");
const { app } = require("./app.js");

const config = getConfig();
setup();

let httpOptions, server;
if (config !== undefined && config["HttpsOptions"] !== undefined) {
Expand Down
5 changes: 5 additions & 0 deletions persistence/file/task.js → app/persistence/file/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ const fs = require("node:fs");
const defaultDataDir = "./data/task/"
const extension = ".json"

function setup() {
fs.mkdirSync(defaultDataDir, {recursive: true});
}

function save(task, callback) {
fs.writeFile(
defaultDataDir + task.id + extension,
Expand Down Expand Up @@ -55,3 +59,4 @@ exports.save = save
exports.load = load
exports.remove = remove
exports.list = list
exports.setup = setup
File renamed without changes.
1 change: 1 addition & 0 deletions docs/bruno/environments/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.local.bru
File renamed without changes.