blob: c5d526d997a252c5f87c84c7550985438efa803a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# Cosmic
Cosmic is a framework build on top of express.
# Installation
## Arch
```bash
pacman -S npm nodejs
git clone https://git.fatalmatrix.xyz/cosmic.git
```
## Debian/Ubuntu
```bash
apt install npm nodejs
git clone https://git.fatalmatrix.xyz/cosmic.git
```
## Configure `nodejs`
Install node modules
```bash
cd cosmic
npm i -g npm@latest # Must be run as root
npm i
```
On Debian/Ubuntu you may get an error due to the nodejs version.
To fix this install `nvm`
```bash
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
# Load nvm
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# Install latest node version
nvm i node
```
Install `npm-check-updates`
```bash
npm install -g npm-check-updates # Must be root
ncu -u
npm i
```
Install `pm2`
```bash
npm i -g pm2 # Must be root
```
Run `ncu -u` to update modules
# Usage
## Create `.env` file
```.env
baseUrl = "http://127.0.0.1:3000/"
emailUsername = "email@email.com"
emailPassword = "password"
NODE_ENV = "dev"
MYSQL_HOST = "127.0.0.1"
MYSQL_USER = "root"
MYSQL_PASSWORD = "Password"
```
On `NODE_ENV` change `dev` to `prod`
## Create `favicon` folder
```bash
mkdir favicon
```
## Create Pages
To create a page write a `class` then add to the `scripts` folder.
```js
class Shop() {
constructor() {}
// GET `/shop`
Main() {
const data = {
start: ``,
body: ``,
end: ``
}
return data.start + data.body + data.end
}
// GET `/shop/product` or POST `/shop/product` and get output from `value`
Product(value) {
const data = {
start: ``,
body: ``,
end: ``
}
return data.start + data.body + data.end
}
// This is required
module.exports = () => {return new Shop()}
}
```
## Layouts
Layouts are located in `views/layouts` if you would like to modify them.
## Blog
Blogs must be a markdown file placed in the `blog` folder
To get the title, date and short description to display you must use the format below
```markdown
# Title
Date: 1/1/1999
---
Short description
---
Content goes here
```
If `blog` folder does not exist
```bash
mkdir blog
```
To get the output for blogs you must lost the `blog.js` module
```js
const blog = require('../source/blog')
blog().ReadBlogs().then(output => {
output.forEach((value, key) => {
console.log(`key: ${key}`)
console.log(value)
})
})
```
## Run
```bash
npm run prod
```
|