Compare commits
4 commits
ca0852800e
...
1eebe45e4e
Author | SHA1 | Date | |
---|---|---|---|
|
1eebe45e4e | ||
|
20240bfdf1 | ||
|
587207f99e | ||
|
dec7600b92 |
7 changed files with 1509 additions and 17 deletions
1
.eslintignore
Normal file
1
.eslintignore
Normal file
|
@ -0,0 +1 @@
|
|||
**/*.js
|
37
.eslintrc.json
Normal file
37
.eslintrc.json
Normal 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
1
.gitignore
vendored
|
@ -2,3 +2,4 @@
|
|||
node_modules
|
||||
built
|
||||
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,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"
|
||||
}
|
||||
}
|
||||
|
|
42
src/index.ts
42
src/index.ts
|
@ -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
6
src/lib/format.ts
Normal 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`;
|
||||
}
|
Loading…
Reference in a new issue