Basic ansible role for installation and some skeleton structure for the server app

This commit is contained in:
sneakers-the-rat 2023-07-24 13:27:36 -07:00
parent 8782834c04
commit 84752f1b30
29 changed files with 8314 additions and 67 deletions

17
.gitignore vendored
View file

@ -129,3 +129,20 @@ dist
.yarn/install-state.gz
.pnp.*
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store

View file

@ -1,4 +1,4 @@
# ucla-chat
# chatbridge
Invite people to a bridged nextcloud chat with a token
@ -25,10 +25,13 @@ Use the ansible role!!!
## References
idk i'm just learnin
- https://typeorm.io/active-record-data-mapper#what-is-the-active-record-pattern
- https://typeorm.io/example-with-express
- https://github.com/wpcodevo/node_typeorm/tree/restapi-node-typeorm
- https://www.axllent.org/docs/nodejs-service-with-systemd/
- https://github.com/wpcodevo/Blog_MUI_React-hook-form/tree/login-signup-form
- https://blog.alexdevero.com/build-react-app-express-api/
- https://www.react.express/
- https://www.typescriptlang.org/docs/handbook/tsconfig-json.html
- https://www.typescriptlang.org/docs/handbook/compiler-options.html
- https://www.typescriptlang.org/docs/handbook/compiler-options.html

10
config/defaults.ts Normal file
View file

@ -0,0 +1,10 @@
export default {
port: '8999',
postgresConfig: {
host: '127.0.0.1',
port: '6500',
username: 'POSTGRES_USER',
password: 'POSTGRES_PASSWORD',
database: 'POSTGRES_DB',
},
}

8
example.env Normal file
View file

@ -0,0 +1,8 @@
PORT=8999
NODE_ENV=development
POSTGRES_HOST=127.0.0.1
POSTGRES_PORT=6500
POSTGRES_USER=
POSTGRES_PASSWORD=
POSTGRES_DB=

11
galaxy.yml Normal file
View file

@ -0,0 +1,11 @@
namespace: "sneakers_the_rat"
name: "chatbridge"
version: 0.1.0
readme: README.md
authors: ["Jonny Saunders <j@nny.fyi>"]
description: Ansible roles for managing chatbridge!
repository: https://git.jon-e.net/jonny/chatbridge
manifest:
directives:
- graft roles

View file

@ -1,5 +1,5 @@
{
"name": "ucla-chat",
"name": "chatbridge",
"version": "1.0.0",
"description": "bridging a bunch of chats together",
"main": "index.js",
@ -12,10 +12,14 @@
"typeorm": "typeorm-ts-node-commonjs",
"migrate": "rm -rf build && yarn build && yarn typeorm migration:generate ./src/migrations/added-user-entity -d ./src/utils/data-source.ts",
"db:push": "rm -rf build && yarn build && yarn typeorm migration:run -d src/utils/data-source.ts",
"importData": "npx ts-node-dev --transpile-only --exit-child src/data/seeder.ts"
"importData": "npx ts-node-dev --transpile-only --exit-child src/data/seeder.ts",
"client_start": "react-scripts start",
"client_build": "react-scripts build",
"client_eject": "react-scripts eject"
},
"dependencies": {
"@slack/oauth": "^2.6.1",
"config": "^3.3.9",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2",
@ -26,6 +30,7 @@
"pug": "^3.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "^5.0.1",
"redis": "^4.6.7",
"typeorm": "^0.3.17",
"typescript": "^5.1.6",
@ -40,5 +45,11 @@
"@types/pug": "^2.0.6",
"ts-node": "^10.9.1",
"ts-node-dev": "^2.0.0"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
}
}

View file

@ -0,0 +1,17 @@
---
# defaults file for chatbridge
chatbridge_postgres_user: chatbridge
chatbridge_postgres_password: CHANGEME
chatbridge_postgres_db: chatbridge
chatbridge_postgres_port: 6500
chatbridge_user: chatbridge
chatbridge_user_home: /var/lib/chatbridge
# Where, beneath the root domain, we should host the site
# (used in nginx configs)
chatbridge_fqdn: localhost
chatbridge_webroot: ""
chatbridge_api_port: 8999

View file

@ -1,7 +1,6 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)
author: Jonny Saunders
description: Install chatbridge :)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
@ -14,7 +13,7 @@ galaxy_info:
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
license: AGPL-3.0-or-later
min_ansible_version: 2.1

View file

@ -0,0 +1,10 @@
- name: clone repository
become: yes
become_user: "{{ chatbridge_user }}"
git:
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"

View file

@ -0,0 +1,24 @@
- name: create development .env
become: yes
become_user: "{{ chatbridge_user }}"
template:
src: chatbridge_env.j2
dest: "{{ chatbridge_user_home}}/.env"
- name: create nginx config
become: yes
template:
src: nginx_chatbridge.conf.j2
dest: /etc/nginx/sites-available/chatbridge.conf
- name: link nginx config
become: yes
file:
state: link
src: /etc/nginx/sites-available/chatbridge.conf
dest: /etc/nginx/sites-enabled/chatbridge.conf
- name: restart nginx
service:
name: nginx
state: restarted

View file

@ -0,0 +1,16 @@
- name: include variable checks
import_tasks: checks.yml
- name: include user config
import_tasks: user.yml
- name: include postgres config
import_tasks: postgres.yml
- name: install chatbridge
import_tasks: chatbridge.yml
- name: configure chatbridge
import_tasks: config.yml

View file

@ -0,0 +1,8 @@
PORT={{ chatbridge_api_port }}
NODE_ENV=development
POSTGRES_HOST=127.0.0.1
POSTGRES_PORT={{ chatbridge_postgres_port }}
POSTGRES_USER={{ chatbridge_postgres_user }}
POSTGRES_PASSWORD={{ chatbridge_postgres_password }}
POSTGRES_DB={{ chatbridge_postgres_db }}

View file

@ -0,0 +1,36 @@
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name {{ chatbridge_fqdn }};
location {{ chatbridge_webroot }}/api/ {
proxy_pass http://127.0.0.1:{{ chatbridge_api_port }}/;
}
location {{ chatbridge_webroot }}/ {
root {{ chatbridge_user_home }}/public;
try_files $uri $uri/ =404;
}
ssl_certificate /etc/letsencrypt/live/{{ chatbridge_fqdn }}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/{{ chatbridge_fqdn }}/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
server {
listen 80;
listen [::]:80;
server_name {{ chatbridge_fqdn }};
location /.well-known/acme-challenge {
root /var/www/letsencrypt;
try_files $uri $uri/ =404;
}
location / {
rewrite ^ https://{{ chatbridge_fqdn }}$request_uri? permanent;
}
}

View file

@ -1,2 +0,0 @@
---
# defaults file for ucla_chat

View file

@ -1,2 +0,0 @@
---
# tasks file for ucla_chat

20
server/app.ts Normal file
View file

@ -0,0 +1,20 @@
require('dotenv').config();
import express, { NextFunction, Request, Response } from 'express';
import config from 'config';
import cors from 'cors';
import { AppDataSource } from './db/data-source';
AppDataSource.initialize()
.then(async () => {
const app = express();
app.all('*', (req: Request, res: Response, next: NextFunction) => {
next(new AppError(404, `Route ${req.originalUrl} not found`));
});
})

22
server/db/data-source.ts Normal file
View file

@ -0,0 +1,22 @@
require('dotenv').config();
import 'reflect-metadata';
import { DataSource } from 'typeorm';
import config from 'config';
const postgresConfig = config.get<{
host: string;
port: number;
username: string;
password: string;
database: string;
}>('postgresConfig');
export const AppDataSource = new DataSource({
...postgresConfig,
type: 'postgres',
synchronize: false,
logging: false,
entities: ['server/entities/**/*.entity{.ts,.js}'],
migrations: ['server/migrations/**/*{.ts,.js}'],
// subscribers: ['server/subscribers/**/*{.ts,.js}'],
});

View file

View file

@ -0,0 +1,17 @@
import {
CreateDateColumn,
UpdateDateColumn,
PrimaryGeneratedColumn,
BaseEntity,
} from 'typeorm';
export default abstract class Model extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
id: string;
@CreateDateColumn()
created_at: Date;
@UpdateDateColumn()
updated_at: Date;
}

View file

@ -0,0 +1,4 @@
/*
Creating and synchronizing the .toml configuration files for matterbridge
*/

View file

@ -0,0 +1,5 @@
/*
Managing the matterbridge processes
*/

17
tsconfig.json Normal file
View file

@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "es2016",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"strictPropertyInitialization": false,
"skipLibCheck": true,
"outDir": "./build",
"rootDir": ".",
"include": ["server/**/*"],
"exclude": ["node_modules", "roles"]
}
}

8106
yarn.lock

File diff suppressed because it is too large Load diff