From bac7b6f275706172a596527a2a04000917add22c Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Mon, 24 Jul 2023 16:15:27 -0700 Subject: [PATCH] running api --- roles/chatbridge/tasks/chatbridge.yml | 3 ++- roles/chatbridge/tasks/config.yml | 2 ++ roles/chatbridge/tasks/user.yml | 11 ++++++++++- .../templates/nginx_chatbridge_http.conf.j2 | 2 +- server/app.ts | 2 +- server/errors/appError.ts | 11 +++++++++++ 6 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 server/errors/appError.ts diff --git a/roles/chatbridge/tasks/chatbridge.yml b/roles/chatbridge/tasks/chatbridge.yml index 213615e..ef95edd 100644 --- a/roles/chatbridge/tasks/chatbridge.yml +++ b/roles/chatbridge/tasks/chatbridge.yml @@ -5,6 +5,7 @@ repo: https://git.jon-e.net/jonny/chatbridge dest: "{{ chatbridge_user_home }}/chatbridge" version: "HEAD" -# failed_when: "command_result.failed and 'Local modifications' not in command_result.msg" + register: command_result + failed_when: "command_result.failed and 'Local modifications' not in command_result.msg" diff --git a/roles/chatbridge/tasks/config.yml b/roles/chatbridge/tasks/config.yml index 405f0f8..b1439ee 100644 --- a/roles/chatbridge/tasks/config.yml +++ b/roles/chatbridge/tasks/config.yml @@ -4,6 +4,7 @@ template: src: chatbridge_env.j2 dest: "{{ chatbridge_user_home}}/.env" + mode: "600" - name: create https nginx config become: yes @@ -20,6 +21,7 @@ template: src: nginx_chatbridge_http.conf.j2 dest: /etc/nginx/sites-available/chatbridge.conf + when: - chatbridge_https is defined - not chatbridge_https diff --git a/roles/chatbridge/tasks/user.yml b/roles/chatbridge/tasks/user.yml index 55970c9..e236050 100644 --- a/roles/chatbridge/tasks/user.yml +++ b/roles/chatbridge/tasks/user.yml @@ -14,11 +14,20 @@ system: true + - name: Create public directory and give permissions to www-data become: yes file: - mode: '660' + mode: '755' state: directory group: "www-data" owner: "{{ chatbridge_user }}" path: "{{ chatbridge_user_home }}/public" + +- name: Chmod home directory + become: yes + file: + mode: '755' + state: directory + group: "www-data" + diff --git a/roles/chatbridge/templates/nginx_chatbridge_http.conf.j2 b/roles/chatbridge/templates/nginx_chatbridge_http.conf.j2 index fc5293f..3578418 100644 --- a/roles/chatbridge/templates/nginx_chatbridge_http.conf.j2 +++ b/roles/chatbridge/templates/nginx_chatbridge_http.conf.j2 @@ -13,7 +13,7 @@ server { } location {{ chatbridge_webroot }}/ { - rewrite ^{{ chatbridge_webroot }}/?(.*)$ $1 break; + rewrite ^{{ chatbridge_webroot }}?(/.*)$ $1 break; root {{ chatbridge_user_home }}/public; try_files $uri $uri/ $uri/index.html =404; } diff --git a/server/app.ts b/server/app.ts index 95ecdac..d2a5dd2 100644 --- a/server/app.ts +++ b/server/app.ts @@ -3,7 +3,7 @@ import express, { NextFunction, Request, Response } from 'express'; import config from 'config'; import cors from 'cors'; import { AppDataSource } from './db/data-source'; - +import AppError from './errors/appError'; diff --git a/server/errors/appError.ts b/server/errors/appError.ts new file mode 100644 index 0000000..fb49745 --- /dev/null +++ b/server/errors/appError.ts @@ -0,0 +1,11 @@ +export default class AppError extends Error { + status: string; + isOperational: boolean; + constructor(public statusCode: number = 500, public message: string) { + super(message); + this.status = `${statusCode}`.startsWith('4') ? 'fail' : 'error'; + this.isOperational = true; + + Error.captureStackTrace(this, this.constructor); + } +}