more moving, add router and example service and controller

main
Fionn 3 years ago
parent b5eafd0a96
commit 57db5860e3

@ -3,10 +3,12 @@
# ################################################################
FROM node:16-alpine as base
WORKDIR /app
WORKDIR /opt
COPY . .
WORKDIR /opt/app
ARG NODE_ENV=production
ENV NODE_ENV ${NODE_ENV}
@ -15,8 +17,6 @@ ENV NODE_ENV ${NODE_ENV}
# ################################################################
FROM base as development
WORKDIR /app
RUN npm install --quiet --unsafe-perm --no-progress --no-audit --include=dev
CMD npm run run:dev
@ -27,8 +27,6 @@ CMD npm run run:dev
FROM base as backendbuild
WORKDIR /app
RUN npm install --quiet --unsafe-perm --no-progress --no-audit --include=dev
RUN npx tsc -p ./tsconfig.json
@ -39,9 +37,7 @@ RUN npx tsc -p ./tsconfig.json
FROM base as production
COPY --from=backendbuild --chown=node:node /app/dist/ /app/dist/
WORKDIR /app
COPY --from=backendbuild --chown=node:node /opt/app/dist/ /opt/app/dist/
RUN npm install --quiet --unsafe-perm --no-progress --no-audit --omit=dev

@ -1,17 +1,20 @@
import express, { NextFunction, Request, Response } from 'express';
import ejsMate from 'ejs-mate';
import router from './router';
const { PORT = 3000 } = process.env;
const app = express();
app.engine('ejs', ejsMate);
app.set('views', '/app/views');
app.set('views', '/opt/app/views');
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) => {
// 404

@ -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,
};

@ -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 };

@ -0,0 +1,7 @@
function getFooDetails() {
return 'foo';
}
export default {
getFooDetails,
};

@ -12,7 +12,7 @@ services:
- '3030:3030/tcp'
- '9229:9229/tcp'
volumes:
- .:/app:delegated
- .:/opt:delegated
environment:
- MONGO_URI
- PORT=3030
Loading…
Cancel
Save