forked from oat/in-the-database-2
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import * as express from 'express';
|
|
import * as mongoose from 'mongoose';
|
|
import * as fs from 'fs';
|
|
|
|
const config = JSON.parse(fs.readFileSync('./config/config.json', {encoding: 'utf8'}));
|
|
|
|
const dbClient = 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 app = express();
|
|
|
|
app.use(express.urlencoded({ extended: true }));
|
|
|
|
app.set('db', dbClient);
|
|
app.set('config', config);
|
|
|
|
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`);
|
|
});
|
|
}); |