add static files

This commit is contained in:
Michael Schramm 2020-06-01 03:40:41 +02:00
parent a8ac338979
commit 866381fc54
9 changed files with 34 additions and 9 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
# compiled output
/dist
/node_modules
/public
# Logs
logs

View File

@ -9,7 +9,7 @@ COPY . .
RUN yarn install --frozen-lockfile
RUN yarn build
FROM node:12-alpine
FROM node:12
WORKDIR /usr/src/app

View File

@ -17,12 +17,13 @@ services:
# environment:
# MONGODB_URI: mongodb://mongo/ohmyform
# MAILER_URI: smtp://mail:1025
# command: yarn start:dev
# PORT: 3000
#command: yarn start:dev
# links:
# - mongo
# - mail
# ports:
# - "6000:3000"
# - "6100:3000"
# depends_on:
# - mongo
mail:

View File

@ -31,6 +31,7 @@
"@nestjs/mongoose": "^6.4.0",
"@nestjs/passport": "^7.0.0",
"@nestjs/platform-express": "^7.0.0",
"@nestjs/serve-static": "^2.1.1",
"@types/html-to-text": "^5.1.0",
"apollo-server-express": "^2.13.0",
"bcrypt": "^4.0.1",

0
public/.gitkeep Normal file
View File

View File

@ -5,6 +5,7 @@ import { GraphQLModule } from '@nestjs/graphql';
import { JwtModule, JwtModuleOptions } from '@nestjs/jwt';
import { MongooseModule } from '@nestjs/mongoose';
import { MongooseModuleOptions } from '@nestjs/mongoose/dist/interfaces/mongoose-options.interface';
import { ServeStaticModule } from '@nestjs/serve-static';
import crypto from 'crypto';
import { Request } from 'express-serve-static-core';
import { IncomingHttpHeaders } from 'http';
@ -40,6 +41,12 @@ export const imports = [
timeout: 5000,
maxRedirects: 10,
}),
ServeStaticModule.forRoot({
rootPath: join(__dirname, '..', 'public'),
exclude: [
]
}),
ConfigModule.forRoot({
load: [
() => {

View File

@ -1,5 +1,6 @@
import { Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { PinoLogger } from 'nestjs-pino/dist';
import { AuthJwtModel } from '../../dto/auth/auth.jwt.model';
import { UserDocument } from '../../schema/user.schema';
import { UserService } from '../user/user.service';
@ -11,17 +12,21 @@ export class AuthService {
private userService: UserService,
private jwtService: JwtService,
private passwordService: PasswordService,
private logger: PinoLogger,
) {}
async validateUser(username: string, password: string): Promise<UserDocument> {
console.log('check user??', username)
// TODO only allow login for verified users!
const user = await this.userService.findByUsername(username);
if (user && await this.passwordService.verify(password, user.passwordHash, user.salt)) {
return user;
try {
const user = await this.userService.findByUsername(username);
if (user && await this.passwordService.verify(password, user.passwordHash, user.salt)) {
return user;
}
} catch (e) {
this.logger.error(`failed to verify user? ${e.message}`)
}
return null;
}

View File

@ -41,12 +41,15 @@ export class BootService implements OnApplicationBootstrap {
return
} catch (e) {}
await this.createService.create({
const user = await this.createService.create({
username,
email,
password,
})
user.set('roles', ['user', 'admin', 'superuser'])
await user.save()
this.logger.info('new root user created')
}
}

View File

@ -768,6 +768,13 @@
"@angular-devkit/schematics" "9.0.6"
fs-extra "8.1.0"
"@nestjs/serve-static@^2.1.1":
version "2.1.1"
resolved "https://registry.yarnpkg.com/@nestjs/serve-static/-/serve-static-2.1.1.tgz#b18573bb14a52fc9ebc82fc887d1bc0846f1d18c"
integrity sha512-hkrCm7R8BWE8k9iiFlRtBIw+/VR4SMWos3yErRvC12y1ADI7gWkbu46+urx8jlcMnOEQW/xTAWY51xe6miBvHQ==
dependencies:
path-to-regexp "0.1.7"
"@nestjs/testing@^7.0.0":
version "7.0.9"
resolved "https://registry.yarnpkg.com/@nestjs/testing/-/testing-7.0.9.tgz#c6b342dd34f060f18406bd7eb753edc5ecbb35c7"