Initial commit - Event Planner application

This commit is contained in:
mberlin
2026-03-18 14:55:56 -03:00
commit 86d779eb4d
7548 changed files with 1006324 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
<img src="/logo.svg" width="100" />
<h1>Static website</h1>
<ul>
<li><a href="/link-1">Link 1</a></li>
<li><a href="/link-2">Link 2</a></li>
<li><a href="/link-3">Link 3</a></li>
</ul>

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -0,0 +1,159 @@
import { INestApplication } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { Server } from 'net';
import request from 'supertest';
import { AppModule } from '../src/app.module';
import { NoopLogger } from '../utils/noop-logger';
describe('Express adapter', () => {
let server: Server;
let app: INestApplication;
describe('when middleware throws generic error', () => {
beforeAll(async () => {
app = await NestFactory.create(AppModule.withDefaults(), {
logger: new NoopLogger()
});
app.use((_req, _res, next) => next(new Error('Something went wrong')));
server = app.getHttpServer();
await app.init();
});
describe('GET /index.html', () => {
it('should return Iternal Server Error', async () => {
return request(server).get('/index.html').expect(500);
});
});
});
describe('when "fallthrough" option is set to "true"', () => {
beforeAll(async () => {
app = await NestFactory.create(AppModule.withFallthrough(), {
logger: new NoopLogger()
});
app.setGlobalPrefix('api');
server = app.getHttpServer();
await app.init();
});
describe('GET /api', () => {
it('should return "Hello, world!"', async () => {
return request(server).get('/api').expect(200).expect('Hello, world!');
});
});
describe('GET /', () => {
it('should return HTML file', async () => {
return request(server)
.get('/')
.expect(200)
.expect('Content-Type', /html/);
});
});
describe('GET /index.html', () => {
it('should return index page', async () => {
return request(server)
.get('/index.html')
.expect(200)
.expect('Content-Type', /html/)
.expect(/Static website/);
});
});
describe('GET /logo.svg', () => {
it('should return logo', async () => {
return request(server)
.get('/logo.svg')
.expect(200)
.expect('Content-Type', /image/);
});
});
describe('when trying to get a non-existing file', () => {
it('should return index page', async () => {
return request(server)
.get('/404')
.expect(200)
.expect('Content-Type', /html/)
.expect(/Static website/);
});
});
afterAll(async () => {
await app.close();
});
});
describe('when "fallthrough" option is set to "false"', () => {
beforeAll(async () => {
app = await NestFactory.create(AppModule.withoutFallthrough(), {
logger: new NoopLogger()
});
app.setGlobalPrefix('api');
server = app.getHttpServer();
await app.init();
});
describe('GET /api', () => {
it('should return "Hello, world!"', async () => {
return request(server).get('/api').expect(200).expect('Hello, world!');
});
});
describe('GET /', () => {
it('should return HTML file', async () => {
return request(server)
.get('/')
.expect(200)
.expect('Content-Type', /html/);
});
});
describe('GET /index.html', () => {
it('should return index page', async () => {
return request(server)
.get('/index.html')
.expect(200)
.expect('Content-Type', /html/)
.expect(/Static website/);
});
});
describe('GET /logo.svg', () => {
it('should return logo', async () => {
return request(server)
.get('/logo.svg')
.expect(200)
.expect('Content-Type', /image/);
});
});
describe('when trying to get a non-existing file', () => {
it('should return 404', async () => {
return request(server)
.get('/404')
.expect(404)
.expect(/Not Found/)
.expect(/ENOENT/);
});
});
describe('when trying to hit a non-existing route under the excluded path', () => {
it('should return 404', async () => {
return request(server)
.get('/api/404')
.expect(404)
.expect(/Not Found/)
.expect(/Cannot GET \/api\/404/);
});
});
afterAll(async () => {
await app.close();
});
});
});

View File

@@ -0,0 +1,193 @@
import { NestFactory } from '@nestjs/core';
import {
FastifyAdapter,
NestFastifyApplication
} from '@nestjs/platform-fastify';
import { AppModule } from '../src/app.module';
import { NoopLogger } from '../utils/noop-logger';
import request from 'supertest';
describe('Fastify adapter', () => {
let app: NestFastifyApplication;
describe('when "fallthrough" option is set to "true"', () => {
beforeAll(async () => {
app = await NestFactory.create(
AppModule.withFallthrough(),
new FastifyAdapter(),
{
logger: new NoopLogger()
}
);
app.setGlobalPrefix('api');
await app.init();
await app.getHttpAdapter().getInstance().ready();
});
describe('GET /api', () => {
it('should return "Hello, world!"', async () => {
return app
.inject({
method: 'GET',
url: '/api'
})
.then((result) => {
expect(result.statusCode).toEqual(200);
expect(result.payload).toEqual('Hello, world!');
});
});
});
describe('GET /', () => {
it('should return HTML file', async () => {
return app
.inject({
method: 'GET',
url: '/'
})
.then((result) => {
expect(result.statusCode).toEqual(200);
expect(result.headers['content-type']).toMatch(/html/);
expect(result.payload).toContain('Static website');
});
});
});
describe('GET /index.html', () => {
it('should return index page', async () => {
return app
.inject({
method: 'GET',
url: '/index.html'
})
.then((result) => {
expect(result.statusCode).toEqual(200);
expect(result.payload).toContain('Static website');
});
});
});
describe('GET /logo.svg', () => {
it('should return logo', async () => {
return app
.inject({
method: 'GET',
url: '/logo.svg'
})
.then((result) => {
expect(result.statusCode).toEqual(200);
expect(result.headers['content-type']).toMatch(/image/);
});
});
});
describe('when trying to get a non-existing file', () => {
it('should returns index page', async () => {
return app
.inject({
method: 'GET',
url: '/404'
})
.then((result) => {
expect(result.statusCode).toEqual(200);
expect(result.payload).toContain('Static website');
});
});
});
afterAll(async () => {
await app.close();
});
});
describe('when "fallthrough" option is set to "false"', () => {
beforeAll(async () => {
app = await NestFactory.create(
AppModule.withoutFallthrough(),
new FastifyAdapter(),
{
logger: new NoopLogger()
}
);
app.setGlobalPrefix('api');
await app.init();
await app.getHttpAdapter().getInstance().ready();
});
describe('GET /api', () => {
it('should return "Hello, world!"', async () => {
return app
.inject({
method: 'GET',
url: '/api'
})
.then((result) => {
expect(result.statusCode).toEqual(200);
expect(result.payload).toEqual('Hello, world!');
});
});
});
describe('GET /', () => {
it('should return HTML file', async () => {
return app
.inject({
method: 'GET',
url: '/'
})
.then((result) => {
expect(result.statusCode).toEqual(200);
expect(result.headers['content-type']).toMatch(/html/);
expect(result.payload).toContain('Static website');
});
});
});
describe('GET /index.html', () => {
it('should return index page', async () => {
return app
.inject({
method: 'GET',
url: '/index.html'
})
.then((result) => {
expect(result.statusCode).toEqual(200);
expect(result.payload).toContain('Static website');
});
});
});
describe('GET /logo.svg', () => {
it('should return logo', async () => {
return app
.inject({
method: 'GET',
url: '/logo.svg'
})
.then((result) => {
expect(result.statusCode).toEqual(200);
expect(result.headers['content-type']).toMatch(/image/);
});
});
});
describe('when trying to get a non-existing file', () => {
it('should return 404', async () => {
return app
.inject({
method: 'GET',
url: '/404'
})
.then((result) => {
expect(result.statusCode).toEqual(404);
});
});
});
afterAll(async () => {
await app.close();
});
});
});

View File

@@ -0,0 +1,9 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"rootDir": ".",
"testEnvironment": "node",
"testRegex": ".spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
}
}

View File

@@ -0,0 +1,9 @@
import { Controller, Get } from '@nestjs/common';
@Controller()
export class AppController {
@Get()
getHello() {
return 'Hello, world!';
}
}

View File

@@ -0,0 +1,51 @@
import { Module } from '@nestjs/common';
import { join } from 'path';
import { ServeStaticModule } from '../../lib';
import { AppController } from './app.controller';
@Module({
controllers: [AppController]
})
export class AppModule {
static withDefaults() {
return {
module: AppModule,
imports: [
ServeStaticModule.forRoot({
rootPath: join(__dirname, '..', 'client'),
exclude: ['/api/{*any}']
})
]
};
}
static withFallthrough() {
return {
module: AppModule,
imports: [
ServeStaticModule.forRoot({
rootPath: join(__dirname, '..', 'client'),
exclude: ['/api/{*any}'],
serveStaticOptions: {
fallthrough: true
}
})
]
};
}
static withoutFallthrough() {
return {
module: AppModule,
imports: [
ServeStaticModule.forRoot({
rootPath: join(__dirname, '..', 'client'),
exclude: ['/api/{*any}'],
serveStaticOptions: {
fallthrough: false
}
})
]
};
}
}

11
node_modules/@nestjs/serve-static/tests/src/main.ts generated vendored Normal file
View File

@@ -0,0 +1,11 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule.withoutFallthrough());
app.setGlobalPrefix('api');
await app.listen(3000);
console.log(`Application is running on: ${await app.getUrl()}`);
}
bootstrap();

View File

@@ -0,0 +1,9 @@
import { ConsoleLogger } from '@nestjs/common';
export class NoopLogger extends ConsoleLogger {
error(message: any, trace?: string, context?: string) {}
warn(message: any, context?: string) {}
log(message: any, context?: string) {}
debug(message: any, context?: string) {}
verbose(message: any, context?: string) {}
}