Disable signups, minor fixes
All checks were successful
ci / build-image (push) Successful in 2m33s

This commit is contained in:
Jonathan Cremin 2025-05-30 09:03:26 +01:00
parent d89c8872d2
commit 0d72c4bf3b
7 changed files with 671 additions and 248 deletions

View file

@ -0,0 +1,39 @@
name: ci
on:
push:
branches: main
jobs:
build-image:
runs-on: self-hosted
steps:
- name: Set current date as env variable
run: echo "NOW=$(date +'%Y%m%d-%H%M%S')" >> $GITHUB_ENV
- name: Fix for bad os check
run: echo "RUNNER_OS=Linux" >> $GITHUB_ENV
- name: Login to Forgejo Registry
uses: https://cremin.dev/actions/podman-login@v1
with:
registry: cremin.dev
username: ${{ github.actor }}
password: ${{ secrets.FORGEJO_REGISTRY_TOKEN }}
- name: Check out repository
uses: https://cremin.dev/actions/checkout@v4
- name: Build image
uses: https://cremin.dev/actions/buildah-build@v2
with:
containerfiles: ./Containerfile
context: ./
oci: true
layers: true
image: hostr
tags: latest ${{ github.sha }}
- name: Push image
uses: https://cremin.dev/actions/push-to-registry@v2
with:
registry: cremin.dev/jonathan
username: ${{ github.actor }}
password: ${{ secrets.FORGEJO_REGISTRY_TOKEN }}
image: hostr
tags: latest ${{ github.sha }}

View file

@ -1,4 +1,4 @@
FROM node:13.13.0
FROM node:16.13.1
WORKDIR /app

77
app.js
View file

@ -1,20 +1,21 @@
import path from 'path';
import Koa from 'koa';
import logger from 'koa-logger';
import serve from 'koa-static';
import favicon from 'koa-favicon';
import compress from 'koa-compress';
import bodyparser from 'koa-bodyparser';
import websockify from 'koa-websocket';
import helmet from 'koa-helmet';
import session from 'koa-session';
import * as Sentry from '@sentry/node';
import debugname from 'debug';
import * as redis from './lib/redis';
import api, { ws } from './api/app';
import web from './web/app';
import path from "path";
import Koa from "koa";
import logger from "koa-logger";
import serve from "koa-static";
import favicon from "koa-favicon";
import compress from "koa-compress";
import bodyparser from "koa-bodyparser";
import websockify from "koa-websocket";
import helmet from "koa-helmet";
import session from "koa-session";
import * as Sentry from "@sentry/node";
import debugname from "debug";
import * as redis from "./lib/redis";
import api, { ws } from "./api/app";
import web from "./web/app";
import { constants } from "zlib";
const debug = debugname('hostr');
const debug = debugname("hostr");
const app = websockify(new Koa());
app.keys = [process.env.COOKIE_KEY];
@ -32,8 +33,8 @@ if (process.env.SENTRY_DSN) {
app.use(helmet());
app.use(async (ctx, next) => {
ctx.set('Server', 'Nintendo 64');
if (ctx.req.headers['x-forwarded-proto'] === 'http') {
ctx.set("Server", "Nintendo 64");
if (ctx.req.headers["x-forwarded-proto"] === "http") {
ctx.redirect(`https://${ctx.req.headers.host}${ctx.req.url}`);
return;
}
@ -42,7 +43,7 @@ app.use(async (ctx, next) => {
} catch (err) {
if (!err.statusCode && process.env.SENTRY_DSN) {
Sentry.captureException(err, (_err, eventId) => {
debug('Reported error', eventId);
debug("Reported error", eventId);
});
}
throw err;
@ -52,26 +53,40 @@ app.use(async (ctx, next) => {
app.use(session(app));
app.use(redis.middleware());
if (app.env === 'development') {
if (app.env === "development") {
app.use(logger());
}
app.use(compress());
app.use(
compress({
filter(content_type) {
return /text/i.test(content_type);
},
threshold: 2048,
gzip: {
flush: constants.Z_SYNC_FLUSH,
},
deflate: {
flush: constants.Z_SYNC_FLUSH,
},
br: false,
}),
);
app.use(favicon(path.join(__dirname, 'web/public/images/favicon.png')));
app.use(serve(path.join(__dirname, 'web/public/'), { maxage: 31536000000 }));
app.use(favicon(path.join(__dirname, "web/public/images/favicon.png")));
app.use(serve(path.join(__dirname, "web/public/"), { maxage: 31536000000 }));
app.use(api.prefix('/api').routes());
app.use(web.prefix('').routes());
app.use(api.prefix("/api").routes());
app.use(web.prefix("").routes());
app.ws.use(redis.middleware());
app.ws.use(ws.prefix('/api').routes());
app.ws.use(ws.prefix("/api").routes());
app.on('error', (err, ctx) => {
app.on("error", (err, ctx) => {
if (err.statusCode === 404) return;
if (process.env.SENTRY_DSN) {
Sentry.withScope(function(scope) {
scope.addEventProcessor(function(event) {
return Sentry.Handlers.parseRequest(event, ctx.request);
Sentry.withScope(function (scope) {
scope.addEventProcessor(function (event) {
return Sentry.Handlers.parseRequest(event, ctx.request);
});
Sentry.captureException(err);
});
@ -81,7 +96,7 @@ app.on('error', (err, ctx) => {
if (!module.parent) {
app.listen(process.env.PORT || 4040, () => {
debug('Koa HTTP server listening on port ', (process.env.PORT || 4040));
debug("Koa HTTP server listening on port ", process.env.PORT || 4040);
});
}

View file

@ -25,7 +25,7 @@ services:
VIRUSTOTAL_KEY:
SENTRY_DSN:
volumes:
- ./:/app
- ./:/app:z
- uploads:/hostr/uploads
- export:/export
ports:
@ -75,7 +75,7 @@ services:
minio:
image: minio/minio
volumes:
- export:/export
- export:/export
command: server /export
environment:
MINIO_ACCESS_KEY: 7HYV3KPRGQ8Z5YCDNWC6

View file

@ -55,9 +55,9 @@
"jimp": "^0.13.0",
"jquery": "^3.5.0",
"kcors": "^2.2.2",
"koa": "^2.11.0",
"koa": "^2.13.4",
"koa-bodyparser": "^4.3.0",
"koa-compress": "~4.0.1",
"koa-compress": "~5.1.0",
"koa-csrf": "^3.0.8",
"koa-error": "^3.2.0",
"koa-favicon": "~2.1.0",
@ -75,7 +75,7 @@
"moment": "^2.24.0",
"mz": "^2.7.0",
"node-fetch": "^2.3.0",
"node-sass": "^4.14.0",
"node-sass": "^7.0.0",
"node-uuid": "^1.4.8",
"passwords": "^1.3.1",
"pg": "^8.0.3",

View file

@ -37,6 +37,10 @@ export async function signin(ctx) {
export async function signup(ctx) {
await ctx.render('signup', { error: 'Signups are disabled.', csrf: ctx.csrf, async: true });
return;
if (!ctx.request.body.email) {
await ctx.render('signup', { csrf: ctx.csrf, async: true });
return;

787
yarn.lock

File diff suppressed because it is too large Load diff