Compare commits
No commits in common. "1eebe45e4e8abbc682eadbbb2e60954e28907b81" and "ca0852800e3f56ffb00b655d9663e5129c6238cf" have entirely different histories.
1eebe45e4e
...
ca0852800e
7 changed files with 17 additions and 1509 deletions
|
@ -1 +0,0 @@
|
||||||
**/*.js
|
|
|
@ -1,37 +0,0 @@
|
||||||
{
|
|
||||||
"env": {
|
|
||||||
"es6": true,
|
|
||||||
"node": true
|
|
||||||
},
|
|
||||||
"extends": [
|
|
||||||
"eslint:recommended",
|
|
||||||
"plugin:@typescript-eslint/eslint-recommended"
|
|
||||||
],
|
|
||||||
"globals": {
|
|
||||||
"Atomics": "readonly",
|
|
||||||
"SharedArrayBuffer": "readonly"
|
|
||||||
},
|
|
||||||
"parser": "@typescript-eslint/parser",
|
|
||||||
"parserOptions": {
|
|
||||||
"ecmaVersion": 2018,
|
|
||||||
"sourceType": "module"
|
|
||||||
},
|
|
||||||
"plugins": [
|
|
||||||
"@typescript-eslint"
|
|
||||||
],
|
|
||||||
"rules": {
|
|
||||||
"indent": [
|
|
||||||
"warn",
|
|
||||||
"tab"
|
|
||||||
],
|
|
||||||
"linebreak-style": "warn",
|
|
||||||
"quotes": [
|
|
||||||
"error",
|
|
||||||
"single"
|
|
||||||
],
|
|
||||||
"semi": [
|
|
||||||
"error",
|
|
||||||
"always"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,5 +1,4 @@
|
||||||
.vscode
|
.vscode
|
||||||
node_modules
|
node_modules
|
||||||
built
|
built
|
||||||
config/config.json
|
config/config.json
|
||||||
*.log
|
|
1421
package-lock.json
generated
1421
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -13,12 +13,6 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"mongoose": "^5.10.2",
|
"mongoose": "^5.10.2",
|
||||||
"typescript": "^4.0.2",
|
"typescript": "^4.0.2"
|
||||||
"winston": "^3.3.3"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@typescript-eslint/eslint-plugin": "^4.0.1",
|
|
||||||
"@typescript-eslint/parser": "^4.0.1",
|
|
||||||
"eslint": "^7.8.1"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
50
src/index.ts
50
src/index.ts
|
@ -1,62 +1,40 @@
|
||||||
import * as express from 'express';
|
import * as express from 'express';
|
||||||
import * as mongoose from 'mongoose';
|
import * as mongoose from 'mongoose';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as winston from 'winston';
|
|
||||||
|
|
||||||
import * as format from './lib/format';
|
|
||||||
|
|
||||||
const config = JSON.parse(fs.readFileSync('./config/config.json', {encoding: 'utf8'}));
|
const config = JSON.parse(fs.readFileSync('./config/config.json', {encoding: 'utf8'}));
|
||||||
|
|
||||||
const db = mongoose.connect(`${config.dbconnectionURL}/${config.dbname}`, {
|
const dbClient = mongoose.connect(`${config.dbconnectionURL}/${config.dbname}`, {
|
||||||
useNewUrlParser: true, // idfk what any of this does i just copied an example
|
useNewUrlParser: true, // idfk what any of this does i just copied an example
|
||||||
useUnifiedTopology: true,
|
useUnifiedTopology: true,
|
||||||
useFindAndModify: false,
|
useFindAndModify: false,
|
||||||
useCreateIndex: true
|
useCreateIndex: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const logger = winston.createLogger({
|
console.log('connecting to mongodb database...');
|
||||||
level: 'info',
|
dbClient.then(() => {
|
||||||
format: winston.format.combine(
|
console.log('connected to database!');
|
||||||
winston.format.timestamp(),
|
|
||||||
winston.format.printf(log => `${format.formatTime(new Date(log.timestamp))} | ${log.message}`)
|
|
||||||
),
|
|
||||||
transports: [
|
|
||||||
new winston.transports.File({filename: `${config.name}-error.log`, level: 'error'}),
|
|
||||||
new winston.transports.File({filename: `${config.name}.log`}),
|
|
||||||
new winston.transports.Console({
|
|
||||||
format: winston.format.combine(
|
|
||||||
winston.format.colorize(),
|
|
||||||
winston.format.timestamp(),
|
|
||||||
winston.format.printf(log =>
|
|
||||||
`${format.formatTime(new Date(log.timestamp))} - [${log.level}] ${log.message}`
|
|
||||||
)
|
|
||||||
),
|
|
||||||
level: process.env.DEBUG === 'true' ? 'silly' : 'info'
|
|
||||||
})
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
logger.info('connecting to mongodb database');
|
|
||||||
db.then(() => {
|
|
||||||
logger.info('connected to database!');
|
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.use(express.urlencoded({ extended: true }));
|
app.use(express.urlencoded({ extended: true }));
|
||||||
|
|
||||||
app.set('db', db);
|
app.set('db', dbClient);
|
||||||
app.set('config', config);
|
app.set('config', config);
|
||||||
app.set('logger', logger);
|
|
||||||
|
|
||||||
app.get('/', (req, res) => {
|
app.get('/', (req, res) => {
|
||||||
res.send(`${config.name} homepage - unfinished`);
|
res.send(`${config.name} homepage - unfinished`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('/recent', (req, res) => {
|
||||||
|
let query = req.query;
|
||||||
|
});
|
||||||
|
|
||||||
app.get('*', (req, res) => {
|
app.get('*', (req, res) => {
|
||||||
res.status(404).send('404');
|
res.status(404).send('404');
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(config.port, () => {
|
app.listen(config.port, () => {
|
||||||
logger.info(`expressjs server launched on port ${config.port}, should now function properly`);
|
console.log(`expressjs server launched on port ${config.port}, should now function properly`);
|
||||||
});
|
});
|
||||||
});
|
});
|
|
@ -1,6 +0,0 @@
|
||||||
export function formatTime(date: Date) : string {
|
|
||||||
const hours = date.getUTCHours();
|
|
||||||
const minutes = date.getUTCMinutes();
|
|
||||||
|
|
||||||
return `${hours < 10 ? '0' : ''}${hours}:${minutes < 10 ? '0' : ''}${minutes} UTC`;
|
|
||||||
}
|
|
Loading…
Reference in a new issue