This commit is contained in:
parent
d89c8872d2
commit
0d72c4bf3b
7 changed files with 671 additions and 248 deletions
39
.forgejo/workflows/build-image.yml
Normal file
39
.forgejo/workflows/build-image.yml
Normal 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 }}
|
|
@ -1,4 +1,4 @@
|
||||||
FROM node:13.13.0
|
FROM node:16.13.1
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
71
app.js
71
app.js
|
@ -1,20 +1,21 @@
|
||||||
import path from 'path';
|
import path from "path";
|
||||||
import Koa from 'koa';
|
import Koa from "koa";
|
||||||
import logger from 'koa-logger';
|
import logger from "koa-logger";
|
||||||
import serve from 'koa-static';
|
import serve from "koa-static";
|
||||||
import favicon from 'koa-favicon';
|
import favicon from "koa-favicon";
|
||||||
import compress from 'koa-compress';
|
import compress from "koa-compress";
|
||||||
import bodyparser from 'koa-bodyparser';
|
import bodyparser from "koa-bodyparser";
|
||||||
import websockify from 'koa-websocket';
|
import websockify from "koa-websocket";
|
||||||
import helmet from 'koa-helmet';
|
import helmet from "koa-helmet";
|
||||||
import session from 'koa-session';
|
import session from "koa-session";
|
||||||
import * as Sentry from '@sentry/node';
|
import * as Sentry from "@sentry/node";
|
||||||
import debugname from 'debug';
|
import debugname from "debug";
|
||||||
import * as redis from './lib/redis';
|
import * as redis from "./lib/redis";
|
||||||
import api, { ws } from './api/app';
|
import api, { ws } from "./api/app";
|
||||||
import web from './web/app';
|
import web from "./web/app";
|
||||||
|
import { constants } from "zlib";
|
||||||
|
|
||||||
const debug = debugname('hostr');
|
const debug = debugname("hostr");
|
||||||
|
|
||||||
const app = websockify(new Koa());
|
const app = websockify(new Koa());
|
||||||
app.keys = [process.env.COOKIE_KEY];
|
app.keys = [process.env.COOKIE_KEY];
|
||||||
|
@ -32,8 +33,8 @@ if (process.env.SENTRY_DSN) {
|
||||||
app.use(helmet());
|
app.use(helmet());
|
||||||
|
|
||||||
app.use(async (ctx, next) => {
|
app.use(async (ctx, next) => {
|
||||||
ctx.set('Server', 'Nintendo 64');
|
ctx.set("Server", "Nintendo 64");
|
||||||
if (ctx.req.headers['x-forwarded-proto'] === 'http') {
|
if (ctx.req.headers["x-forwarded-proto"] === "http") {
|
||||||
ctx.redirect(`https://${ctx.req.headers.host}${ctx.req.url}`);
|
ctx.redirect(`https://${ctx.req.headers.host}${ctx.req.url}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +43,7 @@ app.use(async (ctx, next) => {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (!err.statusCode && process.env.SENTRY_DSN) {
|
if (!err.statusCode && process.env.SENTRY_DSN) {
|
||||||
Sentry.captureException(err, (_err, eventId) => {
|
Sentry.captureException(err, (_err, eventId) => {
|
||||||
debug('Reported error', eventId);
|
debug("Reported error", eventId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
throw err;
|
throw err;
|
||||||
|
@ -52,21 +53,35 @@ app.use(async (ctx, next) => {
|
||||||
app.use(session(app));
|
app.use(session(app));
|
||||||
|
|
||||||
app.use(redis.middleware());
|
app.use(redis.middleware());
|
||||||
if (app.env === 'development') {
|
if (app.env === "development") {
|
||||||
app.use(logger());
|
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(favicon(path.join(__dirname, "web/public/images/favicon.png")));
|
||||||
app.use(serve(path.join(__dirname, 'web/public/'), { maxage: 31536000000 }));
|
app.use(serve(path.join(__dirname, "web/public/"), { maxage: 31536000000 }));
|
||||||
|
|
||||||
app.use(api.prefix('/api').routes());
|
app.use(api.prefix("/api").routes());
|
||||||
app.use(web.prefix('').routes());
|
app.use(web.prefix("").routes());
|
||||||
|
|
||||||
app.ws.use(redis.middleware());
|
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 (err.statusCode === 404) return;
|
||||||
if (process.env.SENTRY_DSN) {
|
if (process.env.SENTRY_DSN) {
|
||||||
Sentry.withScope(function (scope) {
|
Sentry.withScope(function (scope) {
|
||||||
|
@ -81,7 +96,7 @@ app.on('error', (err, ctx) => {
|
||||||
|
|
||||||
if (!module.parent) {
|
if (!module.parent) {
|
||||||
app.listen(process.env.PORT || 4040, () => {
|
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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ services:
|
||||||
VIRUSTOTAL_KEY:
|
VIRUSTOTAL_KEY:
|
||||||
SENTRY_DSN:
|
SENTRY_DSN:
|
||||||
volumes:
|
volumes:
|
||||||
- ./:/app
|
- ./:/app:z
|
||||||
- uploads:/hostr/uploads
|
- uploads:/hostr/uploads
|
||||||
- export:/export
|
- export:/export
|
||||||
ports:
|
ports:
|
||||||
|
|
|
@ -55,9 +55,9 @@
|
||||||
"jimp": "^0.13.0",
|
"jimp": "^0.13.0",
|
||||||
"jquery": "^3.5.0",
|
"jquery": "^3.5.0",
|
||||||
"kcors": "^2.2.2",
|
"kcors": "^2.2.2",
|
||||||
"koa": "^2.11.0",
|
"koa": "^2.13.4",
|
||||||
"koa-bodyparser": "^4.3.0",
|
"koa-bodyparser": "^4.3.0",
|
||||||
"koa-compress": "~4.0.1",
|
"koa-compress": "~5.1.0",
|
||||||
"koa-csrf": "^3.0.8",
|
"koa-csrf": "^3.0.8",
|
||||||
"koa-error": "^3.2.0",
|
"koa-error": "^3.2.0",
|
||||||
"koa-favicon": "~2.1.0",
|
"koa-favicon": "~2.1.0",
|
||||||
|
@ -75,7 +75,7 @@
|
||||||
"moment": "^2.24.0",
|
"moment": "^2.24.0",
|
||||||
"mz": "^2.7.0",
|
"mz": "^2.7.0",
|
||||||
"node-fetch": "^2.3.0",
|
"node-fetch": "^2.3.0",
|
||||||
"node-sass": "^4.14.0",
|
"node-sass": "^7.0.0",
|
||||||
"node-uuid": "^1.4.8",
|
"node-uuid": "^1.4.8",
|
||||||
"passwords": "^1.3.1",
|
"passwords": "^1.3.1",
|
||||||
"pg": "^8.0.3",
|
"pg": "^8.0.3",
|
||||||
|
|
|
@ -37,6 +37,10 @@ export async function signin(ctx) {
|
||||||
|
|
||||||
|
|
||||||
export async function signup(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) {
|
if (!ctx.request.body.email) {
|
||||||
await ctx.render('signup', { csrf: ctx.csrf, async: true });
|
await ctx.render('signup', { csrf: ctx.csrf, async: true });
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue