Skip to content

Commit

Permalink
Server work now
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinhsmith committed Mar 23, 2024
1 parent 22d1d82 commit 7cefae7
Show file tree
Hide file tree
Showing 11 changed files with 638 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,5 @@ dist
conf/
protected/

# Cartel Version
Cartel/
# Cartel Versions
cartel/
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Cartel Server
Cartel Hosting Provider
# Cartel Distribution Server

Host Cartel Data for Packwiz, MultiMC, etc
13 changes: 13 additions & 0 deletions assets/web/views/home.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<h1>Cartel Distribution Server: {{server.name}}</h1>

<h2>Attention Regular Users</h2>

<p>Howdy! This is the home page for a Cartel distribution server. You will not need to be here ever unless your trying to manually patch your Cartel version :P.</p>

<h2>Paths</h2>

<p>Ensure your <code>*.pw.toml</code> and <code>pack.toml</code>/<code>index.toml</code> files point to the following to ensure content delivery:</p>

<p><strong>Packwiz Index Files</strong>: <code>{{server.url}}/download/&lt;version&gt;/&lt;type&gt;/pack.toml</code></p>

<p><strong>Packwiz Resource Files</strong>: <code>{{server.url}}/resource/&lt;version&gt;/&lt;type&gt;?p=&lt;file path&gt;</code></p>
11 changes: 11 additions & 0 deletions assets/web/views/layouts/main.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cartel Dist Server: {{server.name}}</title>
</head>
<body>
{{{body}}}
</body>
</html>
14 changes: 11 additions & 3 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@ const fs = require("fs");
const path = require("path");

const DEFAULT_CONF = {
port: 8080,
protected_dir: path.join(__dirname, "./protected"),
cartel_dir: path.join(__dirname, "./Cartel")
server: {
port: 8080,
name: "Server Name",
url: "Server URL (https://example.com)"
},
cartel: {
latest: "1.0.0",
assets_dir: path.join(__dirname, "./assets"),
pack_dir: path.join(__dirname, "./cartel"),
direct: false
}
}

let final = DEFAULT_CONF;
Expand Down
21 changes: 14 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const http = require("http");
const express = require("express");
const path = require("path");
const {engine} = require('express-handlebars');

// Config
const conf = require("./config")
Expand All @@ -10,14 +11,20 @@ const conf = require("./config")
const app = express();
const server = http.createServer(app);

// Express Routes
app.use("/latest/lite", express.static(path.join(conf.cartel_dir, "./lite")));
app.use("/latest/normal", express.static(path.join(conf.cartel_dir, "./normal")));
app.use("/latest/plus", express.static(path.join(conf.cartel_dir, "./plus")));
// Handlebars
app.engine('hbs', engine({
extname: ".hbs",
defaultLayout: "main"
}));
app.set('view engine', 'hbs');
app.set('views', path.join(__dirname, "./assets/web/views"));

app.use("/protected", express.static(conf.protected_dir));
// Routers
app.use("/resource", require("./routes/resources"));
app.use("/download", require("./routes/download"));
app.use("/", require("./routes/web"));

// Launch
server.listen(conf.port, _ => {
console.info(`Cartel Server Live at *:${conf.port}`);
server.listen(conf.server.port, _ => {
console.info(`Cartel Server Live at *:${conf.server.port}`);
})
Loading

0 comments on commit 7cefae7

Please sign in to comment.