first commit

This commit is contained in:
编码猿
2024-09-27 02:06:13 +08:00
commit 852d94fbb9
36760 changed files with 3274413 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var createError = require("http-errors");
var express = require("express");
var path = require("path");
var cookieParser = require("cookie-parser");
var logger = require("morgan");
var App = (function () {
function App() {
this.port = 3000;
this.AppMain = express();
this.setPlugins();
}
App.prototype.setPlugins = function () {
this.AppMain.set('port', this.port);
this.AppMain.set('views', path.join(__dirname, '../views'));
this.AppMain.set('view engine', 'pug');
this.AppMain.use(logger('dev'));
this.AppMain.use(express.json());
this.AppMain.use(express.urlencoded({ extended: false }));
this.AppMain.use(cookieParser());
this.AppMain.use(express.static(path.join(__dirname, '../public')));
this.setRouter();
};
App.prototype.setRouter = function () {
this.setError();
};
App.prototype.setError = function () {
this.AppMain.use(function (req, res, next) {
next(createError(404));
});
this.AppMain.use(function (err, req, res, next) {
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
res.status(err.status || 500);
res.render('error');
});
};
return App;
}());
exports.App = App;

View File

@@ -0,0 +1,56 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var App_1 = require("./App");
var http = require("http");
var start = (function (_super) {
__extends(start, _super);
function start() {
var _this = _super.call(this) || this;
_this.server = http.createServer(_this.AppMain);
_this.run();
return _this;
}
start.prototype.run = function () {
this.server.listen(this.port);
this.server.on('error', this.onError);
this.server.on('listening', this.onListening);
};
start.prototype.onError = function (error) {
if (error.syscall !== 'listen') {
throw error;
}
var bind = typeof this.port === 'string'
? 'Pipe ' + this.port
: 'Port ' + this.port;
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;
}
};
start.prototype.onListening = function () {
console.log('App is run: http://127.0.0.1:3000');
};
return start;
}(App_1.App));
new start();