Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/dependencies-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
\name: Dependencies CI
name: Dependencies CI

on:
pull_request:
Expand Down
Empty file removed .github/workflows/publish-libs.yml
Empty file.
11 changes: 3 additions & 8 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,9 @@
}
},
"dependencies": {
"@fastify/autoload": "~6.0.3",
"@fastify/cookie": "^11.0.2",
"@fastify/middie": "^9.0.3",
"@fastify/sensible": "~6.0.2",
"@fastify/static": "^8.3.0",
"better-sqlite3": "^12.9.0",
"@rod-manager/plugin-pages-server": "0.0.1",
"@rod-manager/server-platform": "0.0.1",
"dotenv": "^16.4.7",
"fastify": "5.8.3",
"fastify-plugin": "~5.0.1"
"fastify": "^5.8.3"
}
}
28 changes: 0 additions & 28 deletions apps/api/src/app/app.ts

This file was deleted.

101 changes: 0 additions & 101 deletions apps/api/src/app/routes/pages.spec.ts

This file was deleted.

12 changes: 7 additions & 5 deletions apps/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import 'dotenv/config';
import Fastify from 'fastify';
import { existsSync, readFileSync } from 'node:fs';
import type { FastifyInstance } from 'fastify';
import { app } from './app/app';
import { createServerPlatform } from '@rod-manager/server-platform';
import { pagesServerPlugin } from '@rod-manager/plugin-pages-server';

const host = process.env.HOST ?? 'localhost';
const port = process.env.PORT ? Number(process.env.PORT) : 3000;
Expand All @@ -12,7 +13,6 @@ const defaultDevKeyPath = '.cert/localhost-key.pem';
const defaultDevCertPath = '.cert/localhost-cert.pem';
const httpsOptions = getHttpsOptions();

// Instantiate Fastify with some config
const server = Fastify({
logger: true,
https: httpsOptions,
Expand Down Expand Up @@ -44,10 +44,12 @@ function getHttpsOptions() {
};
}

// Register your application as a normal plugin.
server.register(app);
server.register(async (instance) => {
await createServerPlatform(instance, {
plugins: [pagesServerPlugin()],
});
});

// Start listening.
server.listen({ port, host }, (err) => {
if (err) {
server.log.error(err);
Expand Down
5 changes: 4 additions & 1 deletion apps/api/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
],
"references": [
{
"path": "../../libs/shared/tsconfig.lib.json"
"path": "../../libs/server-platform/tsconfig.lib.json"
},
{
"path": "../../libs/plugins/pages/server/tsconfig.lib.json"
}
]
}
7 changes: 6 additions & 1 deletion apps/api/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@
"tsBuildInfoFile": "dist/tsconfig.spec.tsbuildinfo"
},
"include": ["src/**/*.ts"],
"exclude": ["eslint.config.js", "eslint.config.cjs", "eslint.config.mjs"]
"exclude": ["eslint.config.js", "eslint.config.cjs", "eslint.config.mjs"],
"references": [
{
"path": "../../libs/server-platform/tsconfig.lib.json"
}
]
}
1 change: 1 addition & 0 deletions apps/api/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export default defineConfig({
globals: true,
environment: 'node',
include: ['src/**/*.{spec,test}.ts'],
passWithNoTests: true,
},
});
51 changes: 51 additions & 0 deletions libs/plugins/pages/server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "@rod-manager/plugin-pages-server",
"version": "0.0.1",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"@rod-manager/source": "./src/index.ts",
"types": "./dist/index.d.ts",
"require": "./dist/index.js",
"default": "./dist/index.js"
}
},
"files": [
"dist",
"!**/*.tsbuildinfo"
],
"dependencies": {
"@rod-manager/server-platform": "0.0.1",
"@rod-manager/shared": "0.0.1"
},
"nx": {
"targets": {
"typecheck": {
"executor": "nx:run-commands",
"options": {
"cwd": "libs/plugins/pages/server",
"command": "node ../../../../node_modules/typescript/bin/tsc --noEmit -p tsconfig.lib.json && node ../../../../node_modules/typescript/bin/tsc --noEmit -p tsconfig.spec.json"
}
},
"build": {
"executor": "nx:run-commands",
"outputs": [
"{projectRoot}/dist"
],
"options": {
"cwd": "libs/plugins/pages/server",
"command": "node ../../../../node_modules/typescript/bin/tsc --build tsconfig.lib.json"
}
},
"test": {
"executor": "nx:run-commands",
"options": {
"cwd": "libs/plugins/pages/server",
"command": "node ../../../../node_modules/vitest/vitest.mjs run --config vitest.config.mts"
}
}
}
}
}
1 change: 1 addition & 0 deletions libs/plugins/pages/server/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { pagesServerPlugin } from './lib/plugin';
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
import Database from 'better-sqlite3';
import { afterEach, describe, expect, it } from 'vitest';
import { ensurePageSlugValidationRules, initializeSchema } from './init';
import {
pagesSchemaMigration,
pagesValidationRulesMigration,
} from './migrations';
import type { ServerPlatformPluginContext } from '@rod-manager/server-platform';

const databases: Database.Database[] = [];

function createDatabase(): Database.Database {
function createTestContext(): {
db: Database.Database;
ctx: ServerPlatformPluginContext;
} {
const db = new Database(':memory:');
initializeSchema(db);
ensurePageSlugValidationRules(db);
databases.push(db);
return db;
const ctx: ServerPlatformPluginContext = {
fastify: {} as ServerPlatformPluginContext['fastify'],
services: {
authStore: {} as ServerPlatformPluginContext['services']['authStore'],
sessionService:
{} as ServerPlatformPluginContext['services']['sessionService'],
db: db as unknown as ServerPlatformPluginContext['services']['db'],
logger: {} as ServerPlatformPluginContext['services']['logger'],
},
};
void pagesSchemaMigration.up(ctx);
void pagesValidationRulesMigration.up(ctx);
return { db, ctx };
}

afterEach(() => {
Expand All @@ -18,9 +35,9 @@ afterEach(() => {
}
});

describe('page slug validation rules', () => {
describe('pages migrations', () => {
it('rejects slug collision with reserved routes', () => {
const db = createDatabase();
const { db } = createTestContext();

expect(() => {
db.prepare(`INSERT INTO pages (slug, content_md) VALUES (?, ?)`).run(
Expand All @@ -31,7 +48,7 @@ describe('page slug validation rules', () => {
});

it('rejects empty slug values', () => {
const db = createDatabase();
const { db } = createTestContext();

expect(() => {
db.prepare(`INSERT INTO pages (slug, content_md) VALUES (?, ?)`).run(
Expand All @@ -42,7 +59,7 @@ describe('page slug validation rules', () => {
});

it('accepts non-reserved slugs', () => {
const db = createDatabase();
const { db } = createTestContext();

db.prepare(`INSERT INTO pages (slug, content_md) VALUES (?, ?)`).run(
'community-news',
Expand Down
Loading
Loading