Compare commits
8 Commits
cd46524019
...
master
Author | SHA1 | Date | |
---|---|---|---|
63a386416a | |||
f180c96d80 | |||
e4f311b8a6 | |||
08887dcf59 | |||
7cac0a0f5f | |||
4134cab781 | |||
5c3b48859a | |||
f206e014b7 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
|||||||
.vscode
|
.vscode
|
||||||
|
data
|
||||||
|
logs
|
34
Dockerfile
Normal file
34
Dockerfile
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# to build mydraftcc
|
||||||
|
FROM alpine:latest as builder
|
||||||
|
RUN apk add --no-cache nodejs npm git bash
|
||||||
|
RUN git clone https://git.mytinydc.com/Mytinydc/mydraftcc-nodejs-server.git \
|
||||||
|
&& cd mydraftcc-nodejs-server \
|
||||||
|
&& git submodule update --init
|
||||||
|
WORKDIR /mydraftcc-nodejs-server
|
||||||
|
# If you want to patch with "optional"
|
||||||
|
ARG PATCHOPTIONS
|
||||||
|
RUN ./patch.sh "${PATCHOPTIONS}"
|
||||||
|
RUN cd ui && npm install && npm run build
|
||||||
|
|
||||||
|
# Final image server and built ui from previous step
|
||||||
|
FROM alpine:latest as main
|
||||||
|
RUN apk add --no-cache nodejs npm
|
||||||
|
COPY --from=builder /mydraftcc-nodejs-server/server /
|
||||||
|
COPY --from=builder /mydraftcc-nodejs-server/ui/build /public
|
||||||
|
# install and volumes mounpoint logs data
|
||||||
|
RUN npm install \
|
||||||
|
&& mkdir /data /logs
|
||||||
|
|
||||||
|
# run with user/group 1000
|
||||||
|
USER 1000:1000
|
||||||
|
# exposed port
|
||||||
|
EXPOSE 4000
|
||||||
|
# Env Vars
|
||||||
|
ENV IPADDRESS=0.0.0.0
|
||||||
|
ENV PORT=4000
|
||||||
|
# Storage: maximum size of the drawing file
|
||||||
|
# (2Mo : 2 * 1024 * 1024) = 2097152
|
||||||
|
ENV JSONMAXSIZE=2097152
|
||||||
|
|
||||||
|
|
||||||
|
CMD ["/usr/bin/node","/app.js"]
|
69
README.md
69
README.md
@ -1,26 +1,81 @@
|
|||||||
# Minimalist Nodejs server for mydraft application (https:/mydraft.cc)
|
# Minimalist Nodejs server for mydraft application
|
||||||
|
|
||||||
## Installation
|
see :
|
||||||
|
|
||||||
|
- https:/mydraft.cc
|
||||||
|
- https://github.com/mydraft-cc/ui
|
||||||
|
|
||||||
**WARNING** :
|
**WARNING** :
|
||||||
This code is not a fork of "mydraftcc/ui" (https://mydraft.cc), the source code of "mydraftcc/ui" must be available at build time (https://github.com/mydraft-cc/ui).
|
This code is not a fork of "mydraftcc/ui" (https://mydraft.cc), the source code of "mydraftcc/ui" must be available at build time (https://github.com/mydraft-cc/ui).
|
||||||
Once the code is retrieved, i apply patches to make the xxx application compatible with the nodejs API server, and (optional) remove the code related to "UserReport".
|
Once the code is retrieved, i apply patches to make the "mydraftcc/ui" application compatible with the nodejs API server, and (optional) remove the code related to "UserReport".
|
||||||
|
|
||||||
### No docker
|
## Installation
|
||||||
|
|
||||||
|
Legacy or Docker
|
||||||
|
|
||||||
|
### Legacy
|
||||||
|
|
||||||
```
|
```
|
||||||
|
# get sources
|
||||||
|
git clone https://github.com/mydraft-cc/server-node.git --recursive
|
||||||
|
cd server-node
|
||||||
# Required
|
# Required
|
||||||
./patch.sh
|
./patch.sh
|
||||||
# if you want to remove UserReport from the application :
|
# if you want to remove UserReport from the application :
|
||||||
# ./patch.sh "optional"
|
# ./patch.sh "optional"
|
||||||
cd server && npm install && ./start.sh
|
# execute once only to install npm packages and to build ui
|
||||||
|
cd ui && npm install && npm run build && mkdir ../server/{public,data} && cp -R build/* ../server/public/ && cd ..
|
||||||
|
cd server && ./start.sh
|
||||||
#You could set environment parameters in server/start.sh
|
#You could set environment parameters in server/start.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
### Docker
|
### Docker
|
||||||
|
|
||||||
## Execute
|
To build image :
|
||||||
|
|
||||||
|
```
|
||||||
|
docker build --no-cache --force-rm -t mydraftcc-nodejs-server .
|
||||||
|
```
|
||||||
|
|
||||||
|
if you want to remove UserReport from the application, add `--build-arg PATCHOPTIONS=optional` :
|
||||||
|
|
||||||
|
```
|
||||||
|
docker build --build-arg PATCHOPTIONS=optional --no-cache --force-rm -t mydraftcc-nodejs-server .
|
||||||
|
```
|
||||||
|
|
||||||
|
## File webpack.config.js-forlocaldeveloppementwithserver
|
||||||
|
|
||||||
|
Copy this file to "ui/config/webpack.config.js" for debug session. All API request will be sent to the localhost:4000 server...
|
||||||
|
**You need** to apply "patch.sh" before debugging UI with the nodejs server.
|
||||||
|
|
||||||
|
```
|
||||||
|
git submodule update --init
|
||||||
|
cp webpack.config.js-forlocaldeveloppementwithserver ui/config/webpack.config.js
|
||||||
|
./patch.sh
|
||||||
|
cd ui && npm run start
|
||||||
|
## start your debugging session
|
||||||
|
```
|
||||||
|
|
||||||
|
## To use the application
|
||||||
|
|
||||||
|
Once your server is started, just open your favorite Browser (firefox) and enter http://[server Ip address]:4000/
|
||||||
|
|
||||||
## Swagger
|
## Swagger
|
||||||
|
|
||||||
pay **ATTENTION**
|
API documentation could be reached at [your server]:/api-docs/
|
||||||
|
Very usefull to debug API server
|
||||||
|
|
||||||
|
Start the server, and call the page /api-docs, play with API
|
||||||
|
|
||||||
|
```
|
||||||
|
./start.sh
|
||||||
|
# Open browser, call http://localhost:4000/api-docs/
|
||||||
|
```
|
||||||
|
|
||||||
|
## Security
|
||||||
|
|
||||||
|
As you can see, server is not protected by login/password, no TLS transport. You should use it as a personal service.
|
||||||
|
If you decide to expose it on internet, you must installed this service behind reverse proxy (haproxy, nginx) with TLS,
|
||||||
|
**and monitor volume space used**...
|
||||||
|
|
||||||
|
enjoy+++ Damien
|
||||||
|
2
patch.sh
2
patch.sh
@ -6,7 +6,7 @@
|
|||||||
# So default is keeping, to remove from source, execute :
|
# So default is keeping, to remove from source, execute :
|
||||||
# ./patch.sh "optional"
|
# ./patch.sh "optional"
|
||||||
##############################################################
|
##############################################################
|
||||||
|
echo "Option $1"
|
||||||
echo "[INFO]Starting applying patches..."
|
echo "[INFO]Starting applying patches..."
|
||||||
|
|
||||||
## required for nodejs-server
|
## required for nodejs-server
|
||||||
|
@ -19,7 +19,6 @@ class HelperXhr {
|
|||||||
*/
|
*/
|
||||||
static setSettings(req) {
|
static setSettings(req) {
|
||||||
let obj = {};
|
let obj = {};
|
||||||
console.log(req);
|
|
||||||
try {
|
try {
|
||||||
if (req.method.match(/POST|PUT/i)) {
|
if (req.method.match(/POST|PUT/i)) {
|
||||||
obj = Object.keys(req.body).length > 0 ? req.body : {};
|
obj = Object.keys(req.body).length > 0 ? req.body : {};
|
||||||
|
@ -8,7 +8,6 @@ const router = express.Router();
|
|||||||
const HelperXhr = require("HelperXhr");
|
const HelperXhr = require("HelperXhr");
|
||||||
const Libsecurity = require("Libsecurity");
|
const Libsecurity = require("Libsecurity");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = require("path");
|
|
||||||
|
|
||||||
//Dir storage
|
//Dir storage
|
||||||
const datadir = __dirname + "/data";
|
const datadir = __dirname + "/data";
|
||||||
@ -23,7 +22,6 @@ router.post("/", async function (req, res, next) {
|
|||||||
try {
|
try {
|
||||||
//check data received
|
//check data received
|
||||||
let xhr = HelperXhr.setSettings(req);
|
let xhr = HelperXhr.setSettings(req);
|
||||||
console.log(xhr);
|
|
||||||
if (Array.isArray(xhr) && xhr[0].payload.diagramId) {
|
if (Array.isArray(xhr) && xhr[0].payload.diagramId) {
|
||||||
const id = xhr[0].payload.diagramId;
|
const id = xhr[0].payload.diagramId;
|
||||||
if (id) {
|
if (id) {
|
||||||
|
@ -11,6 +11,8 @@ NODEJS="/usr/bin/nodejs"
|
|||||||
if [ ! -f "$NODEJS" ];then
|
if [ ! -f "$NODEJS" ];then
|
||||||
NODEJS="/usr/bin/node"
|
NODEJS="/usr/bin/node"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
npm install
|
||||||
## Start application
|
## Start application
|
||||||
# Parameters
|
# Parameters
|
||||||
# listening ip address
|
# listening ip address
|
||||||
|
Reference in New Issue
Block a user