mirror of
https://github.com/DCsunset/taskwarrior-webui.git
synced 2025-08-18 21:43:06 +02:00
feat(backend): add basic backend server
This commit is contained in:
parent
2de2de0c60
commit
5a92944a5d
8 changed files with 1797 additions and 0 deletions
6
backend/.eslintignore
Normal file
6
backend/.eslintignore
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
# don't ever lint node_modules
|
||||||
|
node_modules
|
||||||
|
# don't lint build output (make sure it's set to your correct build folder name)
|
||||||
|
dist
|
||||||
|
# don't lint nyc coverage output
|
||||||
|
coverage
|
41
backend/.eslintrc.js
Normal file
41
backend/.eslintrc.js
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
module.exports = {
|
||||||
|
'env': {
|
||||||
|
'commonjs': true,
|
||||||
|
'es6': true,
|
||||||
|
'node': true
|
||||||
|
},
|
||||||
|
'parser': '@typescript-eslint/parser',
|
||||||
|
'extends': [
|
||||||
|
'eslint:recommended',
|
||||||
|
'plugin:@typescript-eslint/eslint-recommended',
|
||||||
|
'plugin:@typescript-eslint/recommended'
|
||||||
|
],
|
||||||
|
'globals': {
|
||||||
|
'Atomics': 'readonly',
|
||||||
|
'SharedArrayBuffer': 'readonly'
|
||||||
|
},
|
||||||
|
'parserOptions': {
|
||||||
|
'ecmaVersion': 2018
|
||||||
|
},
|
||||||
|
'rules': {
|
||||||
|
'indent': 'off',
|
||||||
|
'@typescript-eslint/indent': ['warn', 'tab', { SwitchCase: 1 }],
|
||||||
|
'linebreak-style': [
|
||||||
|
'error',
|
||||||
|
'unix'
|
||||||
|
],
|
||||||
|
'quotes': [
|
||||||
|
'error',
|
||||||
|
'single'
|
||||||
|
],
|
||||||
|
'semi': [
|
||||||
|
'error',
|
||||||
|
'always'
|
||||||
|
],
|
||||||
|
'require-atomic-updates': 'off',
|
||||||
|
'brace-style': ['error', 'stroustrup'],
|
||||||
|
'no-throw-literal': 'error',
|
||||||
|
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||||
|
'@typescript-eslint/no-explicit-any': 'off'
|
||||||
|
}
|
||||||
|
};
|
1644
backend/package-lock.json
generated
Normal file
1644
backend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
30
backend/package.json
Normal file
30
backend/package.json
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
{
|
||||||
|
"name": "backend",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "ts-node src/app.ts"
|
||||||
|
},
|
||||||
|
"author": "DCsunset",
|
||||||
|
"license": "GPL-3.0-or-later",
|
||||||
|
"dependencies": {
|
||||||
|
"@koa/router": "^9.0.1",
|
||||||
|
"koa": "^2.13.0",
|
||||||
|
"koa-bodyparser": "^4.3.0",
|
||||||
|
"koa-logger": "^3.2.1",
|
||||||
|
"taskwarrior-lib": "^0.2.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/koa": "^2.11.3",
|
||||||
|
"@types/koa-bodyparser": "^4.3.0",
|
||||||
|
"@types/koa-logger": "^3.1.1",
|
||||||
|
"@types/koa-router": "^7.4.1",
|
||||||
|
"@types/koa__router": "^8.0.2",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^3.5.0",
|
||||||
|
"@typescript-eslint/parser": "^3.5.0",
|
||||||
|
"eslint": "^7.3.1",
|
||||||
|
"ts-node": "^8.10.2",
|
||||||
|
"typescript": "^3.9.5"
|
||||||
|
}
|
||||||
|
}
|
20
backend/src/app.ts
Normal file
20
backend/src/app.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import * as Koa from 'koa';
|
||||||
|
import * as Router from '@koa/router';
|
||||||
|
import * as bodyParser from 'koa-bodyparser';
|
||||||
|
import tasksRouter from './tasks';
|
||||||
|
|
||||||
|
const app = new Koa();
|
||||||
|
|
||||||
|
app.use(bodyParser());
|
||||||
|
|
||||||
|
const router = new Router();
|
||||||
|
router.use(tasksRouter.routes());
|
||||||
|
|
||||||
|
app.use(router.routes());
|
||||||
|
app.use(router.allowedMethods());
|
||||||
|
|
||||||
|
const prod = process.env.NODE_ENV === 'production';
|
||||||
|
const addr = prod ? '0.0.0.0' : 'localhost';
|
||||||
|
app.listen(3000, addr);
|
||||||
|
|
||||||
|
console.log(`Server listening on http://${addr}:3000`);
|
34
backend/src/tasks.ts
Normal file
34
backend/src/tasks.ts
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import * as Router from '@koa/router';
|
||||||
|
|
||||||
|
import taskwarrior from './taskwarrior';
|
||||||
|
|
||||||
|
const router = new Router();
|
||||||
|
|
||||||
|
router.get('/', async ctx => {
|
||||||
|
const tasks = taskwarrior.load();
|
||||||
|
ctx.body = tasks;
|
||||||
|
});
|
||||||
|
|
||||||
|
router.post('/', async ctx => {
|
||||||
|
const msg = taskwarrior.update(ctx.body);
|
||||||
|
console.log(msg);
|
||||||
|
ctx.status = 200;
|
||||||
|
});
|
||||||
|
|
||||||
|
router.put('/', async ctx => {
|
||||||
|
const msg = taskwarrior.update(ctx.body);
|
||||||
|
console.log(msg);
|
||||||
|
ctx.status = 200;
|
||||||
|
});
|
||||||
|
|
||||||
|
router.delete('/', async ctx => {
|
||||||
|
const tasks = ctx.query.tasks;
|
||||||
|
console.log(tasks);
|
||||||
|
/*
|
||||||
|
const msg = taskwarrior.update(tasks);
|
||||||
|
console.log(msg);
|
||||||
|
*/
|
||||||
|
ctx.status = 200;
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
11
backend/src/taskwarrior.ts
Normal file
11
backend/src/taskwarrior.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import { TaskwarriorLib } from 'taskwarrior-lib';
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
|
const prod = process.env.NODE_ENV === 'production';
|
||||||
|
|
||||||
|
const taskwarrior = new TaskwarriorLib(
|
||||||
|
prod ? '~/.taskrc' : path.join(__dirname, '../test/.taskrc'),
|
||||||
|
prod ? '~/.task' : path.join(__dirname, '../test/.task'),
|
||||||
|
);
|
||||||
|
|
||||||
|
export default taskwarrior;
|
11
backend/tsconfig.json
Normal file
11
backend/tsconfig.json
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "commonjs",
|
||||||
|
"target": "es2017",
|
||||||
|
"outDir": "./dist",
|
||||||
|
"sourceMap": true,
|
||||||
|
"strict": true,
|
||||||
|
"baseUrl": "."
|
||||||
|
},
|
||||||
|
"include": ["src"]
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue