more moving, add router and example service and controller
This commit is contained in:
12
Dockerfile
12
Dockerfile
@@ -3,10 +3,12 @@
|
|||||||
# ################################################################
|
# ################################################################
|
||||||
FROM node:16-alpine as base
|
FROM node:16-alpine as base
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /opt
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
WORKDIR /opt/app
|
||||||
|
|
||||||
ARG NODE_ENV=production
|
ARG NODE_ENV=production
|
||||||
ENV NODE_ENV ${NODE_ENV}
|
ENV NODE_ENV ${NODE_ENV}
|
||||||
|
|
||||||
@@ -15,8 +17,6 @@ ENV NODE_ENV ${NODE_ENV}
|
|||||||
# ################################################################
|
# ################################################################
|
||||||
FROM base as development
|
FROM base as development
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
RUN npm install --quiet --unsafe-perm --no-progress --no-audit --include=dev
|
RUN npm install --quiet --unsafe-perm --no-progress --no-audit --include=dev
|
||||||
|
|
||||||
CMD npm run run:dev
|
CMD npm run run:dev
|
||||||
@@ -27,8 +27,6 @@ CMD npm run run:dev
|
|||||||
|
|
||||||
FROM base as backendbuild
|
FROM base as backendbuild
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
RUN npm install --quiet --unsafe-perm --no-progress --no-audit --include=dev
|
RUN npm install --quiet --unsafe-perm --no-progress --no-audit --include=dev
|
||||||
|
|
||||||
RUN npx tsc -p ./tsconfig.json
|
RUN npx tsc -p ./tsconfig.json
|
||||||
@@ -39,9 +37,7 @@ RUN npx tsc -p ./tsconfig.json
|
|||||||
|
|
||||||
FROM base as production
|
FROM base as production
|
||||||
|
|
||||||
COPY --from=backendbuild --chown=node:node /app/dist/ /app/dist/
|
COPY --from=backendbuild --chown=node:node /opt/app/dist/ /opt/app/dist/
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
RUN npm install --quiet --unsafe-perm --no-progress --no-audit --omit=dev
|
RUN npm install --quiet --unsafe-perm --no-progress --no-audit --omit=dev
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,20 @@
|
|||||||
import express, { NextFunction, Request, Response } from 'express';
|
import express, { NextFunction, Request, Response } from 'express';
|
||||||
import ejsMate from 'ejs-mate';
|
import ejsMate from 'ejs-mate';
|
||||||
|
import router from './router';
|
||||||
|
|
||||||
const { PORT = 3000 } = process.env;
|
const { PORT = 3000 } = process.env;
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.engine('ejs', ejsMate);
|
app.engine('ejs', ejsMate);
|
||||||
app.set('views', '/app/views');
|
app.set('views', '/opt/app/views');
|
||||||
app.set('view engine', 'ejs');
|
app.set('view engine', 'ejs');
|
||||||
|
|
||||||
app.use('/dist/bootstrap', express.static('/app/public'));
|
app.use(router.router);
|
||||||
|
|
||||||
app.use(express.static('/app/public'));
|
app.use('/dist/bootstrap', express.static('/opt/app/public'));
|
||||||
|
|
||||||
|
app.use(express.static('/opt/app/public'));
|
||||||
|
|
||||||
app.use((req: Request, res: Response, next: NextFunction) => {
|
app.use((req: Request, res: Response, next: NextFunction) => {
|
||||||
// 404
|
// 404
|
||||||
|
|||||||
14
app/src/controllers/foo.controller.ts
Normal file
14
app/src/controllers/foo.controller.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { Request, Response } from 'express';
|
||||||
|
import fooService from '../services/foo.service';
|
||||||
|
|
||||||
|
function getFoo(req: Request, res: Response) {
|
||||||
|
res.json({
|
||||||
|
foo: true,
|
||||||
|
msg: fooService.getFooDetails(),
|
||||||
|
data: req.body,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
getFoo,
|
||||||
|
};
|
||||||
8
app/src/router.ts
Normal file
8
app/src/router.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { Router } from 'express';
|
||||||
|
import fooController from './controllers/foo.controller';
|
||||||
|
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
router.get('/foo', fooController.getFoo);
|
||||||
|
|
||||||
|
export default { router };
|
||||||
7
app/src/services/foo.service.ts
Normal file
7
app/src/services/foo.service.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
function getFooDetails() {
|
||||||
|
return 'foo';
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
getFooDetails,
|
||||||
|
};
|
||||||
@@ -12,7 +12,7 @@ services:
|
|||||||
- '3030:3030/tcp'
|
- '3030:3030/tcp'
|
||||||
- '9229:9229/tcp'
|
- '9229:9229/tcp'
|
||||||
volumes:
|
volumes:
|
||||||
- .:/app:delegated
|
- .:/opt:delegated
|
||||||
environment:
|
environment:
|
||||||
- MONGO_URI
|
- MONGO_URI
|
||||||
- PORT=3030
|
- PORT=3030
|
||||||
Reference in New Issue
Block a user