diff --git a/.prettierignore b/.prettierignore
new file mode 100644
index 0000000..1a28152
--- /dev/null
+++ b/.prettierignore
@@ -0,0 +1,3 @@
+
+footer.html
+table.html
diff --git a/api/articles.js b/api/articles.js
index 9561b03..4decc8f 100644
--- a/api/articles.js
+++ b/api/articles.js
@@ -1,35 +1,42 @@
const router = require('express').Router()
const { Article } = require('../db/models')
+const buildPage = require('./buildPage')
module.exports = router
router.get('/', async (req, res, next) => {
- try {
- const articles = await Article.findAll()
-
- res.status(201).send(articles)
- } catch (err) {
- next(err)
- }
+ try {
+ const articles = await Article.findAll()
+ const tbl = articles
+ .map(
+ article => `
${article.title} | ${article.link} |
`
+ )
+ .join()
+ const page = buildPage(tbl)
+ console.log(page)
+ res.status(201).send(page)
+ } catch (err) {
+ next(err)
+ }
})
router.get('/:id', async (req, res, next) => {
- try {
- const article = await Article.findById(req.params.id)
- console.log(article.title)
- console.log("by: " + article.author)
- console.log(article.text)
- res.status(201).send(article)
- } catch (err) {
- next(err)
- }
+ try {
+ const article = await Article.findById(req.params.id)
+ console.log(article.title)
+ console.log('by: ' + article.author)
+ console.log(article.text)
+ res.status(201).send(article)
+ } catch (err) {
+ next(err)
+ }
})
router.post('/', async (req, res, next) => {
- const body = req.body
- try {
- const article = await Article.create(body)
- res.redirect(article.id)
- } catch (err) {
- next(err)
- }
+ const body = req.body
+ try {
+ const article = await Article.create(body)
+ res.redirect(article.id)
+ } catch (err) {
+ next(err)
+ }
})
diff --git a/api/buildPage.js b/api/buildPage.js
new file mode 100644
index 0000000..6450d5c
--- /dev/null
+++ b/api/buildPage.js
@@ -0,0 +1,22 @@
+module.exports = listString =>
+ `
+
+
+
+ Haxor Newz
+ "uber l337"
+
+
+ Title |
+ Link |
+
+ ${listString}
+
+ ATTACK!
+
+
+
+
+
+
+`
diff --git a/db/models/article.js b/db/models/article.js
index 838ae14..613c3e7 100644
--- a/db/models/article.js
+++ b/db/models/article.js
@@ -2,19 +2,13 @@ const Sequelize = require('sequelize')
const db = require('../db')
const Article = db.define('articles', {
- title: {
- type: Sequelize.STRING,
- allowNull: false
- },
- author: {
- type: Sequelize.STRING,
- defaultValue: "anonymous"
- },
-
- text: {
- type: Sequelize.TEXT,
- allowNull: false
- },
+ title: {
+ type: Sequelize.STRING,
+ allowNull: false
+ },
+ link: {
+ type: Sequelize.STRING
+ }
})
module.exports = Article
diff --git a/db/seed.js b/db/seed.js
index 3d28fb4..046112a 100755
--- a/db/seed.js
+++ b/db/seed.js
@@ -1,37 +1,28 @@
const db = require('../db')
-const fs = require("fs")
+const fs = require('fs')
const { Item, Article } = require('./models')
-const desert = fs.readFileSync("/home/notnull/projex/bootstrap/server/db/desert.txt", "utf8")
-
-
-const testItem = {
- name: 'item'
-}
-
const testArticle = {
- title: "Desert",
- text: desert
-
+ title: 'read desert',
+ link: 'https://readdesert.org'
}
-console.log(Article)
+console.log(Article)
async function runSeed() {
- await db.sync({ force: true })
- console.log('db synced!')
- console.log('seeding...')
- try {
- await Item.create(testItem)
- await Article.create(testArticle)
- console.log('seeded successfully')
- } catch (err) {
- console.error(err)
- process.exitCode = 1
- } finally {
- console.log('closing db connection')
- await db.close()
- console.log('db connection closed')
- }
+ await db.sync({ force: true })
+ console.log('db synced!')
+ console.log('seeding...')
+ try {
+ await Article.create(testArticle)
+ console.log('seeded successfully')
+ } catch (err) {
+ console.error(err)
+ process.exitCode = 1
+ } finally {
+ console.log('closing db connection')
+ await db.close()
+ console.log('db connection closed')
+ }
}
runSeed()
diff --git a/index.js b/index.js
index aebfe80..f6b4dfa 100755
--- a/index.js
+++ b/index.js
@@ -13,12 +13,8 @@ app.use(express.urlencoded({ extended: true }))
app.use(require('body-parser').text())
app.use('/api', require('./api'))
-if (process.env.NODE_ENV === 'production') {
- // Express will serve up production assets
- app.use(express.static(path.join(__dirname, '..', 'client', 'build')))
-}
app.get('*', (req, res) =>
- res.sendFile(path.resolve(__dirname, '..', 'client', 'public', 'index.html'))
+ res.sendFile(path.resolve(__dirname, 'public', 'articles.html'))
)
// error handling endware
diff --git a/public/add.html b/public/add.html
new file mode 100644
index 0000000..edb78c3
--- /dev/null
+++ b/public/add.html
@@ -0,0 +1,16 @@
+
+
+
+ Haxor Newz
+ "uber l337"
+
+
+
+ Ⓐ anarchy planet
+
+
diff --git a/public/index.html b/public/index.html
new file mode 100644
index 0000000..47f93ef
--- /dev/null
+++ b/public/index.html
@@ -0,0 +1,16 @@
+
+
+
+ Haxor Newz
+ "uber l337"
+
+
+
+
+
+