mirror of
https://github.com/Zandercraft/TechnicFlux.git
synced 2026-10-30 04:49:20 +00:00
Add initial server files.
This commit is contained in:
43
app.js
Normal file
43
app.js
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
const createError = require('http-errors')
|
||||||
|
const express = require('express')
|
||||||
|
const path = require('path')
|
||||||
|
const cookieParser = require('cookie-parser')
|
||||||
|
const logger = require('morgan')
|
||||||
|
|
||||||
|
const indexRouter = require('./routes/index')
|
||||||
|
const usersRouter = require('./routes/users')
|
||||||
|
const apiRouter = require('./routes/api')
|
||||||
|
|
||||||
|
const app = express()
|
||||||
|
|
||||||
|
// view engine setup
|
||||||
|
app.set('views', path.join(__dirname, 'views'))
|
||||||
|
app.set('view engine', 'hbs')
|
||||||
|
|
||||||
|
app.use(logger('dev'))
|
||||||
|
app.use(express.json())
|
||||||
|
app.use(express.urlencoded({ extended: false }))
|
||||||
|
app.use(cookieParser())
|
||||||
|
app.use(express.static(path.join(__dirname, 'public')))
|
||||||
|
|
||||||
|
app.use('/', indexRouter)
|
||||||
|
app.use('/users', usersRouter)
|
||||||
|
app.use('/api', apiRouter)
|
||||||
|
|
||||||
|
// catch 404 and forward to error handler
|
||||||
|
app.use(function (req, res, next) {
|
||||||
|
next(createError(404))
|
||||||
|
})
|
||||||
|
|
||||||
|
// error handler
|
||||||
|
app.use(function (err, req, res, next) {
|
||||||
|
// set locals, only providing error in development
|
||||||
|
res.locals.message = err.message
|
||||||
|
res.locals.error = req.app.get('env') === 'development' ? err : {}
|
||||||
|
|
||||||
|
// render the error page
|
||||||
|
res.status(err.status || 500)
|
||||||
|
res.render('error')
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = app
|
||||||
90
bin/www
Normal file
90
bin/www
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module dependencies.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var app = require('../app');
|
||||||
|
var debug = require('debug')('technicflux:server');
|
||||||
|
var http = require('http');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get port from environment and store in Express.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var port = normalizePort(process.env.PORT || '3000');
|
||||||
|
app.set('port', port);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create HTTP server.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var server = http.createServer(app);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listen on provided port, on all network interfaces.
|
||||||
|
*/
|
||||||
|
|
||||||
|
server.listen(port);
|
||||||
|
server.on('error', onError);
|
||||||
|
server.on('listening', onListening);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize a port into a number, string, or false.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function normalizePort(val) {
|
||||||
|
var port = parseInt(val, 10);
|
||||||
|
|
||||||
|
if (isNaN(port)) {
|
||||||
|
// named pipe
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (port >= 0) {
|
||||||
|
// port number
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event listener for HTTP server "error" event.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onError(error) {
|
||||||
|
if (error.syscall !== 'listen') {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
var bind = typeof port === 'string'
|
||||||
|
? 'Pipe ' + port
|
||||||
|
: 'Port ' + port;
|
||||||
|
|
||||||
|
// handle specific listen errors with friendly messages
|
||||||
|
switch (error.code) {
|
||||||
|
case 'EACCES':
|
||||||
|
console.error(bind + ' requires elevated privileges');
|
||||||
|
process.exit(1);
|
||||||
|
break;
|
||||||
|
case 'EADDRINUSE':
|
||||||
|
console.error(bind + ' is already in use');
|
||||||
|
process.exit(1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event listener for HTTP server "listening" event.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onListening() {
|
||||||
|
var addr = server.address();
|
||||||
|
var bind = typeof addr === 'string'
|
||||||
|
? 'pipe ' + addr
|
||||||
|
: 'port ' + addr.port;
|
||||||
|
debug('Listening on ' + bind);
|
||||||
|
}
|
||||||
3676
package-lock.json
generated
Normal file
3676
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
47
package.json
Normal file
47
package.json
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
{
|
||||||
|
"name": "technicflux",
|
||||||
|
"prettyName": "TechnicFlux",
|
||||||
|
"description": "A feature-rich and easy-to-use implementation of Technic's Solder API using Node.js.",
|
||||||
|
"author": {
|
||||||
|
"name": "Zandercraft",
|
||||||
|
"email": "support@zandercraft.ca",
|
||||||
|
"url": "https://zandercraft.ca/"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/Zandercraft/TechnicFlux/issues",
|
||||||
|
"email": "support@zandercraft.ca"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/Zandercraft/TechnicFlux/",
|
||||||
|
"keywords": [
|
||||||
|
"technic",
|
||||||
|
"solder",
|
||||||
|
"technicsolder",
|
||||||
|
"flux",
|
||||||
|
"technicflux",
|
||||||
|
"minecraft",
|
||||||
|
"modding",
|
||||||
|
"zandercraft",
|
||||||
|
"modpacks",
|
||||||
|
"mods",
|
||||||
|
"vcs",
|
||||||
|
"versioning",
|
||||||
|
"dashboard",
|
||||||
|
"api"
|
||||||
|
],
|
||||||
|
"version": "0.0.1",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"start": "node ./bin/www"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"cookie-parser": "~1.4.4",
|
||||||
|
"current-git-branch": "^1.1.0",
|
||||||
|
"debug": "~4.3.4",
|
||||||
|
"express": "~4.16.1",
|
||||||
|
"hbs": "~4.2.0",
|
||||||
|
"http-errors": "~1.6.3",
|
||||||
|
"morgan": "~1.9.1",
|
||||||
|
"standard": "^17.1.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
8
public/stylesheets/style.css
Normal file
8
public/stylesheets/style.css
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
body {
|
||||||
|
padding: 50px;
|
||||||
|
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #00B7FF;
|
||||||
|
}
|
||||||
114
routes/api.js
Normal file
114
routes/api.js
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
const express = require('express')
|
||||||
|
const pckg = require('../package.json')
|
||||||
|
const branchName = require('current-git-branch');
|
||||||
|
const router = express.Router()
|
||||||
|
|
||||||
|
router.get('/', (req, res) => {
|
||||||
|
res.json({
|
||||||
|
"api": pckg.prettyName,
|
||||||
|
"version": pckg.version,
|
||||||
|
"stream": branchName()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
router.get('/mod/:modname', (req, res) => {
|
||||||
|
// Found
|
||||||
|
res.json({
|
||||||
|
"id": 0,
|
||||||
|
"name": "example",
|
||||||
|
"pretty_name": "Example",
|
||||||
|
"author": "ExampleAuthor",
|
||||||
|
"description": "This is the description",
|
||||||
|
"link": "https://example.com/",
|
||||||
|
"versions": [
|
||||||
|
"1.20.1-0.0.1",
|
||||||
|
"1.20.1-0.0.2"
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
// Not Found
|
||||||
|
// res.status(404).json({
|
||||||
|
// "error": "Mod does not exist"
|
||||||
|
// })
|
||||||
|
})
|
||||||
|
|
||||||
|
router.get('/mod/:modname/:modversion', (req, res) => {
|
||||||
|
// Found
|
||||||
|
res.json({
|
||||||
|
"id": 0,
|
||||||
|
"md5": "51c1305b56249804926e38fcf3e46640",
|
||||||
|
"filesize": 0,
|
||||||
|
"url": "https://example.com/file.zip",
|
||||||
|
})
|
||||||
|
|
||||||
|
// Mod Not Found
|
||||||
|
// res.status(404).json({
|
||||||
|
// "error": "Mod does not exist"
|
||||||
|
// })
|
||||||
|
|
||||||
|
// Version Not Found
|
||||||
|
// res.status(404).json({
|
||||||
|
// "error": "Mod version does not exist"
|
||||||
|
// })
|
||||||
|
})
|
||||||
|
|
||||||
|
router.get('/modpack', (req, res) => {
|
||||||
|
// No Slug
|
||||||
|
res.json({
|
||||||
|
"modpacks": {
|
||||||
|
"test": "Example Modpack"
|
||||||
|
},
|
||||||
|
"mirror_url": "https://example.com/"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
router.get('/modpack/:slug', (req, res) => {
|
||||||
|
// With Slug
|
||||||
|
res.json({
|
||||||
|
"name": "examplepack",
|
||||||
|
"display_name": "Example Pack",
|
||||||
|
"recommended": "0.0.1",
|
||||||
|
"latest": "0.0.2",
|
||||||
|
"builds": [
|
||||||
|
"0.0.1",
|
||||||
|
"0.0.2"
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
// Modpack Not Found
|
||||||
|
// res.status(404).json({
|
||||||
|
// "error": "Modpack does not exist"
|
||||||
|
// })
|
||||||
|
})
|
||||||
|
|
||||||
|
router.get('/modpack/:slug/:build', (req, res) => {
|
||||||
|
// Build found
|
||||||
|
res.json({
|
||||||
|
"minecraft": "1.20.1",
|
||||||
|
"forge": null,
|
||||||
|
"java": 17,
|
||||||
|
"memory": 2048,
|
||||||
|
"mods": [
|
||||||
|
{
|
||||||
|
"name": "examplemod",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"md5": "51c1305b56249804926e38fcf3e46640",
|
||||||
|
"url": "https://example.com/file.zip",
|
||||||
|
"filesize": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// Modpack Not Found
|
||||||
|
// res.status(404).json({
|
||||||
|
// "error": "Modpack does not exist"
|
||||||
|
// })
|
||||||
|
|
||||||
|
// Build Not Found
|
||||||
|
// res.status(404).json({
|
||||||
|
// "error": "Build does not exist"
|
||||||
|
// })
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = router
|
||||||
9
routes/index.js
Normal file
9
routes/index.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
const express = require('express')
|
||||||
|
const router = express.Router()
|
||||||
|
|
||||||
|
/* GET home page. */
|
||||||
|
router.get('/', function (req, res, next) {
|
||||||
|
res.render('index', { title: 'Express' })
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = router
|
||||||
9
routes/users.js
Normal file
9
routes/users.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
const express = require('express')
|
||||||
|
const router = express.Router()
|
||||||
|
|
||||||
|
/* GET users listing. */
|
||||||
|
router.get('/', function (req, res, next) {
|
||||||
|
res.send('respond with a resource')
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = router
|
||||||
3
views/error.hbs
Normal file
3
views/error.hbs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<h1>{{message}}</h1>
|
||||||
|
<h2>{{error.status}}</h2>
|
||||||
|
<pre>{{error.stack}}</pre>
|
||||||
2
views/index.hbs
Normal file
2
views/index.hbs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
<h1>{{title}}</h1>
|
||||||
|
<p>Welcome to {{title}}</p>
|
||||||
10
views/layout.hbs
Normal file
10
views/layout.hbs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>{{title}}</title>
|
||||||
|
<link rel='stylesheet' href='/stylesheets/style.css' />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{{{body}}}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user