Skip to content

feat: waas 2.0 (rewrite) #240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
36 changes: 0 additions & 36 deletions .devcontainer/devcontainer.json

This file was deleted.

38 changes: 0 additions & 38 deletions .devcontainer/docker-compose.yml

This file was deleted.

3 changes: 0 additions & 3 deletions .editorconfig

This file was deleted.

44 changes: 21 additions & 23 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,27 @@ on:

jobs:
test:
# Linux runner
runs-on: ubuntu-latest
# Container image that the job will run in
container: python:3.10

# Service containers
services:
redis:
image: redis
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
cache: "npm"
node-version-file: ".nvmrc"

- name: Install dependencies
run: pip install -r requirements.txt
- name: Install requirements (ffmpeg)
run: |
apt-get update
apt-get install -y ffmpeg
- name: Test with pytest
run: |
pytest
run: npm ci

- name: Run format
run: npm run format

- name: Run lint
run: npm run lint

- name: Run check
run: npm run check

- name: Run build
run: npm run build
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,5 @@ testfiles
#Uploads
upload-shared-tmp

.turbo
node_modules
4 changes: 4 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
save-exact=true
engine-strict=true
loglevel = "warn"
fund=false
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v22
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"biomejs.biome",
"github.vscode-github-actions",
"astro-build.astro-vscode"
]
}
19 changes: 19 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"github-enterprise.uri": "https://github.schibsted.io",
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true,
"[javascript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[typescript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[json]": {
"editor.defaultFormatter": "biomejs.biome"
},
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"quickfix.biome": "explicit",
"source.organizeImports.biome": "explicit"
}
}
11 changes: 0 additions & 11 deletions Dockerfile

This file was deleted.

22 changes: 0 additions & 22 deletions Dockerfile.gpu

This file was deleted.

1 change: 1 addition & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_PORT=3000
28 changes: 28 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "api",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"build": "rm -rf dist && tsc -p tsconfig.json",
"start": "node dist/index.js",
"dev": "nodemon --ext ts --exec 'npm run build && dotenv -- npm start'"
},
"dependencies": {
"@fastify/autoload": "6.0.2",
"@fastify/compress": "8.0.1",
"@fastify/sensible": "6.0.1",
"@promster/fastify": "14.0.0",
"dotenv": "16.4.5",
"fastify": "5.1.0",
"fastify-healthcheck": "5.1.0"
},
"devDependencies": {
"@types/node": "22.9.0",
"dotenv-cli": "7.4.2",
"nodemon": "3.1.7",
"ts-node-dev": "2.0.0",
"tsconfig": "*",
"typescript": "5.6.3"
}
}
92 changes: 92 additions & 0 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import autoload from '@fastify/autoload';
import compress from '@fastify/compress';
import sensible from '@fastify/sensible';
import {
getContentType as getPrometheusContentType,
getSummary as getPrometheusSummary,
plugin as promsterPlugin,
} from '@promster/fastify';
import fastify from 'fastify';
import healthcheck from 'fastify-healthcheck';

import path from 'node:path';
import { fileURLToPath } from 'node:url';
import zlib from 'node:zlib';

const port = Number(process.env.API_PORT || 3000);

// Create a Fastify instance
const server = fastify({
logger: {
level: process.env.NODE_ENV === 'development' ? 'info' : 'error',
},

exposeHeadRoutes: true,
ignoreTrailingSlash: true,
forceCloseConnections: true,
});

// Register plugins
server.register(sensible);
server.register(compress, {
threshold: 1,
brotliOptions: {
params: {
[zlib.constants.BROTLI_PARAM_MODE]: zlib.constants.BROTLI_MODE_TEXT,
[zlib.constants.BROTLI_PARAM_QUALITY]: 6,
},
},
zlibOptions: {
level: 6,
},
});
server.register(healthcheck, {
healthcheckUrl: '/_health',
exposeUptime: true,
});
server.register(promsterPlugin, {
skip: (req, _res, _labels) => {
// @ts-expect-error
if (['/_metrics', '/_health'].includes(req.url)) {
return true;
}
return false;
},
});

// Register metric endpoints
server.get('/_metrics', (req, reply) => {
getPrometheusSummary()
.then((summary) => {
reply.type(getPrometheusContentType()).send(summary);
})
.catch((err) => {
req.log.error(err);
reply.code(500).send();
});
});

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// Register routes
server.register(autoload, {
dir: path.join(__dirname, 'routes'),
options: { prefix: '/api/v2' },
});

// Start the server and listen on the specified port
const start = async () => {
try {
await server.listen({ port, host: '0.0.0.0' });
} catch (err) {
server.log.error(err);
process.exit(1);
}
};

start();

process.on('unhandledRejection', (e) => {
console.error(e);
});
Loading
Loading