Set API https

This commit is contained in:
Anthony Mineo 2020-08-31 17:12:04 -04:00
parent 87bfab307d
commit 80056903c6
3 changed files with 14 additions and 7 deletions

View file

@ -1,3 +1,4 @@
import * as fs from 'fs';
import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
@ -5,7 +6,13 @@ import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
// Use local gen'd cert in container
const httpsOptions = {
key: fs.readFileSync('/localcert/key.pem', 'utf8'),
cert: fs.readFileSync('/localcert/cert.pem', 'utf8')
};
const app = await NestFactory.create(AppModule, { httpsOptions });
app.enableCors({
credentials: true
@ -33,6 +40,6 @@ async function bootstrap() {
const document = SwaggerModule.createDocument(app, swaggerOptions);
SwaggerModule.setup('docs', app, document);
await app.listen(8080);
await app.listen(8443);
}
bootstrap();

View file

@ -23,7 +23,7 @@ RUN apk update && apk add --no-cache openssl bash curl
# Default envs as prod
ENV HOST=0.0.0.0 \
PORT=8080 \
PORT=8443 \
NODE_ENV=production \
APP_NAME=NestJS
@ -42,7 +42,7 @@ WORKDIR /opt/node_app
#USER node
# Generate a localhost cert
# RUN openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout /localcert/key.pem -out /localcert/cert.pem -subj "/C=US/ST=New Jersey/L=Warren/O=localhost/OU=IT/CN=127.0.0.1"
RUN openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout /localcert/key.pem -out /localcert/cert.pem -subj "/C=US/ST=New Jersey/L=Warren/O=localhost/OU=IT/CN=127.0.0.1"
ENV PATH /opt/node_app/node_modules/.bin:$PATH
@ -62,9 +62,9 @@ COPY ./app/api/package.json ./app/api/package-lock.json* ./
COPY ./build/api/ecosystem._PROD_.config.js /opt/node_app/ecosystem._PROD_.config.js
COPY ./build/api/entrypoint.sh /entrypoint.sh
EXPOSE 8080
EXPOSE 8080 8443
HEALTHCHECK --interval=20s --timeout=30s --start-period=5s --retries=5 \
CMD curl -f -k http://localhost:8080/ || exit 1
CMD curl -f -k https://localhost:8443/ || exit 1
ENTRYPOINT [ "/entrypoint.sh" ]

View file

@ -44,7 +44,7 @@ services:
replicas: 1
api:
image: "amineo/t2-stats-api:v0.0.2"
image: "amineo/t2-stats-api:v0.0.3"
build:
context: .
dockerfile: ./build/api/Dockerfile