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
10 changes: 7 additions & 3 deletions src/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { I18nContext } from 'nestjs-i18n';
import { AppService } from './app.service';
import { ConfigService } from '@nestjs/config';

Expand All @@ -15,9 +16,12 @@ describe('AppController', () => {
appController = app.get<AppController>(AppController);
});

describe('root', () => {
it('should be "Hello World!"', () => {
expect(appController.getHello()?.message).toBe('Hello World!');
describe('index', () => {
it('should return a context object with translated pageTitle', () => {
const i18n = { t: (key: string) => key } as unknown as I18nContext;
expect(appController.index(i18n)).toEqual({
pageTitle: 'lang.PAGE_TITLE_HOME',
});
});
});
});
26 changes: 22 additions & 4 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import {
Logger,
Post,
Render,
Req,
Res,
Sse,
} from '@nestjs/common';
import { Subject } from 'rxjs';
import { AppService } from './app.service';
import { I18n, I18nContext } from 'nestjs-i18n';
import { FastifyReply, FastifyRequest } from 'fastify';

@Controller()
export class AppController {
Expand All @@ -20,10 +24,8 @@ export class AppController {

@Get()
@Render('index')
getHello(): any {
return {
message: this.appService.getHello(),
};
index(@I18n() i18n: I18nContext) {
return { pageTitle: i18n.t('lang.PAGE_TITLE_HOME') };
}

@Get('chat')
Expand Down Expand Up @@ -97,4 +99,20 @@ export class AppController {
well_known() {
return {}; // Just return empty object
}

@Get('sitemap.xml')
sitemap(@Req() req: FastifyRequest, @Res() reply: FastifyReply): void {
const baseUrl = `${req.protocol}://${req.host}`;
reply.header('Content-Type', 'application/xml; charset=utf-8');
reply.send(
`<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>${baseUrl}/</loc>
<changefreq>weekly</changefreq>
<priority>1.0</priority>
</url>
</urlset>`,
);
}
}
4 changes: 2 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
PORT: Joi.number().default(3000),
APP_NAME: Joi.string().default('Boilerplate'),
AUTH_ENABLED: Joi.boolean().default(false),
PWA_ENABLED: Joi.boolean().default(false),
DISABLE_REGISTRATION: Joi.boolean().default(false),
PWA_ENABLED: Joi.boolean().default(false),
ACCESS_TOKEN_SECRET: Joi.string().default('ChangeMe!'),
PUBLIC_VAPID_KEY: Joi.optional().default(
'BEl62iUYgUivxIkv69yViEuiBIa-Ib9-SkvMeAtA3LFgDzkrxZJjSgSnfckjBJuBkr3qBUYIHBQFLXYp5Nksh8U',
Expand All @@ -89,7 +89,7 @@
.when('DATABASE_TYPE', {
is: 'sqlite',
then: Joi.string().default((parent) =>
path.join(parent.DATA_PATH, 'sqlite3.db'),

Check warning on line 92 in src/app.module.ts

View workflow job for this annotation

GitHub Actions / back-end-ci

Unsafe argument of type `any` assigned to a parameter of type `string`
),
})
.when('DATABASE_TYPE', {
Expand Down Expand Up @@ -208,6 +208,6 @@
async onModuleInit(): Promise<void> {
this.logger.log(`NODE_ENV: ${this.configService.get('NODE_ENV')}`);
this.logger.log(`DATA_PATH: ${this.configService.get('DATA_PATH')}`);
await this.orm.getMigrator().up();
await this.orm.migrator.up();
}
}
2 changes: 1 addition & 1 deletion src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { EmailService } from '../email/email.service';
import { PasswordReset } from '../dal/entity/passwordReset.entity';
import { randomInt } from 'crypto';
import { ResetPasswordDto } from './dto/resetPassword.dto';
import * as Handlebars from 'handlebars';
import Handlebars from 'handlebars';
import { readFileSync } from 'fs';
import { join } from 'path';

Expand Down
2 changes: 0 additions & 2 deletions src/file/controller/file.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
Controller,
Get,
Header,
Inject,
Logger,
Param,
Post,
Expand All @@ -25,7 +24,6 @@ export class FileController {
private logger = new Logger(FileController.name);

constructor(
@Inject(FileService)
private readonly fileService: FileService,
@InjectRepository(UserEntity)
private readonly userRepository: EntityRepository<UserEntity>,
Expand Down
4 changes: 2 additions & 2 deletions src/file/s3-file/s3-file.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EntityManager } from '@mikro-orm/core';
import { getRepositoryToken } from '@mikro-orm/nestjs';
import { ConfigService } from '@nestjs/config';
import { Test, TestingModule } from '@nestjs/testing';
import { S3Module, S3ModuleOptions } from 'nestjs-s3';
import { S3Module } from 'nestjs-s3';
import { File } from '../../dal/entity/file.entity';
import { S3FileService } from './s3-file.service';

Expand All @@ -20,7 +20,7 @@ describe('S3FileService', () => {
s3ForcePathStyle: true,
signatureVersion: 'v4',
},
} as S3ModuleOptions),
}),
],
providers: [
S3FileService,
Expand Down
1 change: 1 addition & 0 deletions src/i18n/en/lang.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"APP_DESCRIPTION": "A rapid web application development boilerplate built on NestJS, HTMX, Tailwind, DaisyUI, MikroORM, and more.",
"PAGE_TITLE_HOME": "Lazztech.Boilerplate - rapid web application development boilerplate",
"TAGLINE": "Ship faster with a proven full-stack boilerplate",
"HERO_DESCRIPTION": "A decade of engineering experience distilled into an opinionated, production-ready starting point for modern web apps. Built on NestJS, HTMX, Tailwind, DaisyUI, MikroORM, and more.",
"GET_STARTED": "Get Started",
Expand Down
12 changes: 7 additions & 5 deletions views/layout.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ https://nestjs-i18n.com/quick-start --}}
https://htmx.org/attributes/hx-swap/#modifiers --}}
<meta name="htmx-config" content='{"globalViewTransitions": "true"}' />
{{!-- https://htmx.org/quirks/#attribute-inheritance --}}
<meta name="htmx-config" content='{"disableInheritance":true}'>
<meta name="htmx-config" content='{"disableInheritance":true}' />

<title>{{appName}}</title>
{{! Used inconjunction with service worker sw.js to enable PWA (Progressive
Expand All @@ -58,10 +58,12 @@ https://nestjs-i18n.com/quick-start --}}
user experience where the body gets swapped out without a full page reload
similar to a SPA. https://htmx.org/attributes/hx-boost/
https://htmx.org/quirks/#some-people-don-t-like-hx-boost

safe-area-inset-bottom ensures smartphone nav doesnt interfere with UI.
}}
<body hx-boost="true" hx-ext="sse" class="h-screen flex flex-col bottom-[calc(4rem+env(safe-area-inset-bottom,0px))]">
safe-area-inset-bottom ensures smartphone nav doesnt interfere with UI. }}
<body
hx-boost="true"
hx-ext="sse"
class="h-screen flex flex-col bottom-[calc(4rem+env(safe-area-inset-bottom,0px))]"
>
{{! Caution: Triple brackets in handlebarsjs disables auto-escaping and may
pose a XSS risk with HTMX. However the exception to this rule is when
loading hbs rendered content which is pre-santized by the handlebars
Expand Down
Loading