F
This commit is contained in:
parent
26524549c1
commit
df2afd36e2
@ -12,9 +12,9 @@
|
|||||||
|
|
||||||
"rules": {
|
"rules": {
|
||||||
"quotes": ["warn", "single"],
|
"quotes": ["warn", "single"],
|
||||||
"semi": ["warn", "never"],
|
"semi": ["error", "never"],
|
||||||
"indent": ["warn", 2],
|
"indent": ["warn", 2],
|
||||||
"no-unused-vars": ["warn"],
|
"no-unused-vars": ["warn"],
|
||||||
"no-console": 0
|
"no-console": ["off"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"trailingComma": "es5",
|
|
||||||
"tabWidth": 4,
|
|
||||||
"semi": false,
|
|
||||||
"singleQuote": true
|
|
||||||
}
|
|
50
db/seed.js
50
db/seed.js
@ -1,27 +1,41 @@
|
|||||||
const db = require('../db')
|
const db = require("../db");
|
||||||
const { Article } = require('./models')
|
const { Article, Comment, User } = require("./models");
|
||||||
|
// WHYYYYYYY
|
||||||
const testArticle = {
|
const testArticle = {
|
||||||
title: 'read desert',
|
title: "read desert",
|
||||||
link: 'https://readdesert.org'
|
link: "https://readdesert.org"
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const testComment = {
|
||||||
|
title: "best essay ever",
|
||||||
|
content: "read the sand book already!"
|
||||||
|
};
|
||||||
|
|
||||||
|
const testUser = {
|
||||||
|
nick: "nn"
|
||||||
|
};
|
||||||
|
|
||||||
console.log(Article)
|
|
||||||
async function runSeed() {
|
async function runSeed() {
|
||||||
await db.sync({ force: true })
|
await db.sync({ force: true });
|
||||||
console.log('db synced!')
|
console.log("db synced!");
|
||||||
console.log('seeding...')
|
console.log("seeding...");
|
||||||
try {
|
try {
|
||||||
await Article.create(testArticle)
|
const article = await Article.create(testArticle);
|
||||||
console.log('seeded successfully')
|
|
||||||
|
const user = await User.create(testUser);
|
||||||
|
const c1 = await Comment.create(testComment);
|
||||||
|
c1.addUser(user);
|
||||||
|
article.addUser(user);
|
||||||
|
article.addComment(c1);
|
||||||
|
console.log("seeded successfully");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err);
|
||||||
process.exitCode = 1
|
process.exitCode = 1;
|
||||||
} finally {
|
} finally {
|
||||||
console.log('closing db connection')
|
console.log("closing db connection");
|
||||||
await db.close()
|
await db.close();
|
||||||
console.log('db connection closed')
|
console.log("db connection closed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
runSeed()
|
runSeed();
|
||||||
|
48
index.js
48
index.js
@ -1,41 +1,41 @@
|
|||||||
const express = require('express');
|
const express = require('express')
|
||||||
const path = require('path');
|
const path = require('path')
|
||||||
const morgan = require('morgan');
|
const morgan = require('morgan')
|
||||||
const ascii = require('./ascii');
|
const ascii = require('./ascii')
|
||||||
const db = require('./db');
|
const db = require('./db')
|
||||||
|
|
||||||
const app = express();
|
const app = express()
|
||||||
const port = process.env.PORT || 1337;
|
const port = process.env.PORT || 1337
|
||||||
|
|
||||||
db.authenticate()
|
db.authenticate()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log('Connection has been established successfully.');
|
console.log('Connection has been established successfully.')
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error('Unable to connect to the database:', err);
|
console.error('Unable to connect to the database:', err)
|
||||||
});
|
})
|
||||||
|
|
||||||
app.use(morgan('tiny'));
|
app.use(morgan('tiny'))
|
||||||
|
|
||||||
// body parsing middleware
|
// body parsing middleware
|
||||||
app.use(express.json());
|
app.use(express.json())
|
||||||
app.use(express.urlencoded({ extended: true }));
|
app.use(express.urlencoded({ extended: true }))
|
||||||
app.use(require('body-parser').text());
|
app.use(require('body-parser').text())
|
||||||
app.use('/api', require('./api'));
|
app.use('/api', require('./api'))
|
||||||
|
|
||||||
app.get('*', (req, res) =>
|
app.get('*', (req, res) =>
|
||||||
res.sendFile(path.resolve(__dirname, 'public', 'articles.html'))
|
res.sendFile(path.resolve(__dirname, 'public', 'articles.html'))
|
||||||
);
|
)
|
||||||
|
|
||||||
// error handling endware
|
// error handling endware
|
||||||
app.use((err, req, res, next) => {
|
app.use((err, req, res, next) => {
|
||||||
console.error(err);
|
console.error(err)
|
||||||
console.error(err.stack);
|
console.error(err.stack)
|
||||||
res.status(err.status || 500).send(err.message || 'Internal server error.');
|
res.status(err.status || 500).send(err.message || 'Internal server error.')
|
||||||
next();
|
next()
|
||||||
});
|
})
|
||||||
|
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log(`\n${ascii}\n`);
|
console.log(`\n${ascii}\n`)
|
||||||
console.log(`Doin' haxor stuff on port ${port}`);
|
console.log(`Doin' haxor stuff on port ${port}`)
|
||||||
});
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user