Skip to content

Commit

Permalink
fix: flow dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamensuli committed Jul 3, 2024
1 parent 5fbe862 commit d576cf4
Show file tree
Hide file tree
Showing 85 changed files with 2,278 additions and 1,972 deletions.
59 changes: 59 additions & 0 deletions bin/renew-letsencrypt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

# Nom du service web
WEB_SERVICE='nginx'
# Chemin de base (à personnaliser)
BASE_PATH="/path/to/your/project"
# Fichier de configuration de Certbot
CONFIG_FILE="$BASE_PATH/nodefony/config/letsencrypt/webroot.ini"
# Limite de jours avant expiration pour renouveler le certificat
EXP_LIMIT=180

# Vérifie si le fichier de configuration existe
if [ ! -f "$CONFIG_FILE" ]; then
echo "[ERROR] Config file does not exist: $CONFIG_FILE"
exit 1
fi

# Extraction des domaines depuis le fichier de configuration
DOMAINS=$(awk -F= '/^\s*domains\s*=/{gsub(/ /, "", $2); print $2}' "$CONFIG_FILE")
# Filtrage pour obtenir le premier domaine sans sous-domaine
DOMAIN=$(echo "$DOMAINS" | tr ',' '\n' | grep -E '^[^.]+\.[^.]+$' | head -n 1)
# Vérifie si un domaine sans sous-domaine a été trouvé
if [ -z "$DOMAIN" ]; then
echo "[ERROR] No valid domain without subdomain found in the config file: $CONFIG_FILE"
exit 1
fi
# Chemin vers le fichier du certificat
BASE_CERT_PATH="/etc/letsencrypt/live"
CERT_FILE="$BASE_CERT_PATH/$DOMAIN/fullchain.pem"

# Vérifie si le fichier de certificat existe
if [ ! -f "$CERT_FILE" ]; then
echo "[ERROR] Certificate file not found for domain $DOMAIN."
exit 1
fi

# Variables pour les dates
DATE_NOW=$(date -d "now" +%s)
EXP_DATE=$(date -d "$(openssl x509 -in "$CERT_FILE" -text -noout | grep "Not After" | cut -c 25-)" +%s)
EXP_DAYS=$(((EXP_DATE - DATE_NOW) / 86400))

echo "Checking expiration date for $DOMAIN..."
echo "Expiration date: $(date -d @$EXP_DATE)"
echo "Days until expiration: $EXP_DAYS"

# Vérifie si le certificat doit être renouvelé
if [ "$EXP_DAYS" -gt "$EXP_LIMIT" ]; then
echo "The certificate is up to date, no need for renewal ($EXP_DAYS days left)."
exit 0
else
echo "The certificate for $DOMAIN is about to expire soon. Starting webroot renewal script..."
certbot certonly --webroot --renew-by-default --config "$CONFIG_FILE" --quiet --renew-hook "systemctl reload $WEB_SERVICE"
if [ $? -ne 0 ]; then
echo "[ERROR] Certbot failed to renew the certificate for $DOMAIN"
exit 1
fi
echo "Renewal process finished for domain $DOMAIN"
exit 0
fi
7 changes: 4 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from "node:path";
//import { resolve } from "node:path";
import { Kernel, Module, modules } from "nodefony";
import { controllers } from "@nodefony/framework";
import config from "./nodefony/config/config";
Expand All @@ -8,6 +8,7 @@ import config from "./nodefony/config/config";
//import sequelize from "@nodefony/sequelize";
//import Test from "@nodefony/test";
import AppController from "./nodefony/controllers/AppController";
import indexController from "./nodefony/controllers/indexController";

/**
* The App class extends the Module class and represents an application entry point.
Expand All @@ -22,7 +23,7 @@ import AppController from "./nodefony/controllers/AppController";
//Test,
//"@nodefony/redis",
])
@controllers([AppController])
@controllers([AppController, indexController])
class App extends Module {
/**
* Constructs an instance of the App class.
Expand All @@ -39,7 +40,7 @@ class App extends Module {
* @param kernel - An instance of the Kernel class.
* @returns A promise that resolves to the instance of the App class.
*/
async initialize(kernel: Kernel): Promise<this> {
async initialize(_kernel: Kernel): Promise<this> {
// if (
// this.kernel?.environment === "production" ||
// this.kernel?.environment === "staging"
Expand Down
14 changes: 7 additions & 7 deletions nodefony/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* "^.*\\.nodefony\\.eu$"
* ]
*/
import path from "node:path";
//import path from "node:path";
import { Nodefony } from "nodefony";
const kernel = Nodefony.kernel;
import http from "./modules/http-config";
Expand All @@ -30,9 +30,9 @@ import pm2 from "./pm2/pm2.config";

let CDN = null;
let statics = true;
let monitoring = true;
let documentation = true;
let unitTest = true;
//let monitoring = true;
//let documentation = true;
//let unitTest = true;
let domainCheck = false;

switch (kernel?.environment) {
Expand All @@ -41,9 +41,9 @@ switch (kernel?.environment) {
default:
CDN = null;
statics = true;
documentation = true;
monitoring = true;
unitTest = true;
//documentation = true;
//monitoring = true;
//unitTest = true;
domainCheck = true;
}
//console.log(sequelize.connectors.nodefony.options);
Expand Down
14 changes: 14 additions & 0 deletions nodefony/config/letsencrypt/webroot.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# We use a 4096 bit RSA key instead of 2048
rsa-key-size = 4096

email = [email protected]

# multi domain separator <,>
#domains = nodefony.com, www.nodefony.com, static.nodefony.com
domains = domain.fr,domain.com,www.domain.com,static.domain.com

authenticator = webroot

# This is the webroot directory of your domain in which
# letsencrypt will write a hash in /.well-known/acme-challenge directory.
webroot-path =/path/to/your/project/public
2 changes: 1 addition & 1 deletion nodefony/config/modules/sequelize-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from "path";
import nodefony, { Kernel } from "nodefony";
import { sequelize } from "@nodefony/sequelize";
//import { sequelize } from "@nodefony/sequelize";

const config = {
connectors: {
Expand Down
32 changes: 24 additions & 8 deletions nodefony/controllers/AppController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolve } from "node:path";
import { inject, Fetch, FileClass } from "nodefony";
//import { inject, Fetch, FileClass } from "nodefony";
import { route, controller, Controller } from "@nodefony/framework";
import { ContextType } from "@nodefony/http";

Expand All @@ -22,7 +22,25 @@ class AppController extends Controller {
"views",
"index.twig"
);
return this.renderTwigView(view, this.context?.metaData).catch((e) => {
return this.renderTwig(view, this.context?.metaData).catch((e) => {
throw e;
});
}
@route("route-app-render-viex", { path: "/view", method: "GET" })
async method2() {
// const view = resolve(
// this.module?.path as string,
// "nodefony",
// "views",
// "index.twig"
// );
const view = resolve(
this.module?.path as string,
"nodefony",
"views",
"index.ejs"
);
return this.renderView(view, this.context?.metaData).catch((e) => {
throw e;
});
}
Expand All @@ -31,18 +49,16 @@ class AppController extends Controller {
path: "/ejs",
requirements: { methods: ["GET"] },
})
async method4(name: string) {
async method4() {
const view = resolve(
this.module?.path as string,
"nodefony",
"views",
"index.ejs"
);
return this.renderEjsView(view, { name, ...this.context?.metaData }).catch(
(e) => {
throw e;
}
);
return this.renderEjs(view, { ...this.context?.metaData }).catch((e) => {
throw e;
});
}
}

Expand Down
25 changes: 25 additions & 0 deletions nodefony/controllers/indexController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { route, controller, Controller } from "@nodefony/framework";
import { ContextType } from "@nodefony/http";

@controller("")
class IndexController extends Controller {
constructor(context: ContextType) {
super("index", context);
}

async initialize() {
await this.startSession("app");
return this;
}

@route("route-index-default", { path: "", method: "GET" })
async index() {
return this.forward("app:AppController:method1");
}
@route("route-index-default2", { path: "/", method: "GET" })
async index2() {
return this.forward("app:AppController:method1");
}
}

export default IndexController;
1 change: 0 additions & 1 deletion nodefony/views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@

<body>
<h1><%= nodefony.name %> EJS</h1>
<h1><%= name %></h1>
</body>
</html>
Loading

0 comments on commit d576cf4

Please sign in to comment.