Skip to content

Commit

Permalink
Creating Server:
Browse files Browse the repository at this point in the history
created structure of the server side adding folders and app.js
  • Loading branch information
Nico committed Nov 24, 2022
1 parent 404aa2d commit 981af8c
Show file tree
Hide file tree
Showing 7,095 changed files with 796,029 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
72 changes: 72 additions & 0 deletions server/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@



//require framework and middleware dependencies
const express = require('express');
const path = require('path');
const logger = require('morgan');
const methodOverride = require('method-override');
const multer = require('multer');

const ejsc = require('ejsc-views');

const fs = require('fs-extra');



//init framework
const app = express();



app.use(logger('dev'));
app.use(express.urlencoded({ extended: false })); // parse application/x-www-form-urlencoded
app.use(express.json({limit: '4MB'})); // parse application/json
app.use(multer().none()); //parse multipart/form-data

app.use(express.static(path.join(__dirname, 'public'), {index: "index.html"}));


app.set('view engine', 'html');

ejsc.compile(views_dir = "views", output_dir = "public/js", details = false);

//co

// TODO - controllers


// TODO - add routes here

//default fallback handlers
// catch 404 and forward to error handler
app.use(function(req, res, next) {
const err = new Error('Not Found');
err.status = 404;
next(err);
});

app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.json({
message: err.message,
error: err
});
});


//start server
app.set('port', process.env.PORT || 8888);

var server = require('http').createServer(app);

server.on('listening', function() {
console.log('Express server listening on port ' + server.address().port);
});

// TODO websocket server

server.listen(app.get('port'));



39 changes: 39 additions & 0 deletions server/ejs-compile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const fs = require('fs-extra');
const ejs = require('ejs');
const glob = require('glob-fs')({ gitignore: true });

function compile(view) {

//let v = path.basename(view, '.ejs');

let v = view.replace(/\//g,"_").replace(/\.ejs$/,"");

console.log(v);

let template = new String(fs.readFileSync(view));
let f = ejs.compile(template, {client:true});

let f_str = f.toString();

f_str = f_str.replace("function anonymous(","ejs."+v+" = function(").replace("function(locals, escapeFn, include, rethrow", "function(locals, escapeFn, include = ejs.views_include(locals), rethrow")

return f_str;

}

//let compiled = fs.readdirSync("views").filter(f=>f.endsWith(".ejs")).map(f=>`views/${f}`).map(compile).join("\n\n");

let compiled = glob.readdirSync("views/**/*.ejs").map(compile).join("\n\n");

let output = `//EJS Compiled Views - This file was automatically generated on ${new Date()}
ejs.views_include = function(locals) {
console.log("views_include_setup",locals);
return function(path, d) {
console.log("ejs.views_include",path,d);
return ejs["views_"+path.replace(/\\\//g,"_")]({...d,...locals}, null, ejs.views_include(locals));
}
};
${compiled}`

fs.writeFile("public/js/views.js", output);

1 change: 1 addition & 0 deletions server/node_modules/.bin/_mocha

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/node_modules/.bin/ejs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/node_modules/.bin/ejsc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/node_modules/.bin/flat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/node_modules/.bin/fxparser

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/node_modules/.bin/he

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/node_modules/.bin/jake

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/node_modules/.bin/js-yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/node_modules/.bin/mkdirp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/node_modules/.bin/mocha

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/node_modules/.bin/nanoid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/node_modules/.bin/semver

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/node_modules/.bin/uuid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/node_modules/.bin/which

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

502 changes: 502 additions & 0 deletions server/node_modules/.yarn-integrity

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions server/node_modules/@aws-crypto/ie11-detection/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 981af8c

Please sign in to comment.