Compare commits

...

4 commits

Author SHA1 Message Date
oat
1eebe45e4e
wow. what a dumb variable name 2020-09-02 16:19:29 +03:00
oat
20240bfdf1
log go bye 2020-09-02 16:18:19 +03:00
oat
587207f99e
funny eslint
what i find funny is i already fucked up and ive only made a boilerplate
2020-09-02 16:17:26 +03:00
oat
dec7600b92
set up logger 2020-09-02 16:12:05 +03:00
7 changed files with 1509 additions and 17 deletions

1
.eslintignore Normal file
View file

@ -0,0 +1 @@
**/*.js

37
.eslintrc.json Normal file
View file

@ -0,0 +1,37 @@
{
"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"
]
}
}

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
node_modules
built
config/config.json
*.log

1421
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -13,6 +13,12 @@
"dependencies": {
"express": "^4.17.1",
"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"
}
}

View file

@ -1,40 +1,62 @@
import * as express from 'express';
import * as mongoose from 'mongoose';
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 dbClient = mongoose.connect(`${config.dbconnectionURL}/${config.dbname}`, {
const db = mongoose.connect(`${config.dbconnectionURL}/${config.dbname}`, {
useNewUrlParser: true, // idfk what any of this does i just copied an example
useUnifiedTopology: true,
useFindAndModify: false,
useCreateIndex: true
});
console.log('connecting to mongodb database...');
dbClient.then(() => {
console.log('connected to database!');
const logger = winston.createLogger({
level: 'info',
format: winston.format.combine(
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();
app.use(express.urlencoded({ extended: true }));
app.set('db', dbClient);
app.set('db', db);
app.set('config', config);
app.set('logger', logger);
app.get('/', (req, res) => {
res.send(`${config.name} homepage - unfinished`);
});
app.get('/recent', (req, res) => {
let query = req.query;
});
app.get('*', (req, res) => {
res.status(404).send('404');
});
app.listen(config.port, () => {
console.log(`expressjs server launched on port ${config.port}, should now function properly`);
logger.info(`expressjs server launched on port ${config.port}, should now function properly`);
});
});

6
src/lib/format.ts Normal file
View file

@ -0,0 +1,6 @@
export function formatTime(date: Date) : string {
const hours = date.getUTCHours();
const minutes = date.getUTCMinutes();
return `${hours < 10 ? '0' : ''}${hours}:${minutes < 10 ? '0' : ''}${minutes} UTC`;
}