minor changes
This commit is contained in:
parent
6f5768195a
commit
8307b2960d
@ -14,6 +14,7 @@
|
||||
"quotes": ["warn", "single"],
|
||||
"semi": ["warn", "never"],
|
||||
"indent": ["warn", 2],
|
||||
"no-unused-vars": ["warn"]
|
||||
"no-unused-vars": ["warn"],
|
||||
"no-console": 0
|
||||
}
|
||||
}
|
||||
|
6
README.md
Normal file
6
README.md
Normal file
@ -0,0 +1,6 @@
|
||||
# Server
|
||||
a minimal working example for the backend of a crud app built with node, express, postgres, sequelize
|
||||
|
||||
|
||||
# TODO
|
||||
- [ ] get rid of proxy
|
@ -1,14 +1,16 @@
|
||||
const router = require('express').Router()
|
||||
const path = require('path')
|
||||
module.exports = router
|
||||
const ascii = require('../ascii')
|
||||
|
||||
router.use('/items', require('./items'))
|
||||
router.use('/articles', require('./articles'))
|
||||
|
||||
router.get('/', async (req, res, next) => {
|
||||
try {
|
||||
res.send('/n-------/nHello from Express!/n--------/n')
|
||||
res.json({ ascii })
|
||||
} catch (err) {
|
||||
next(err)
|
||||
console.log(err)
|
||||
next()
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
curl -d {"title":"", "text": ""} -H Content-Type: application/json -X POST http://localhost:1337/api/articles
|
5
db/OLFDODSJFsetupProxy.js
Normal file
5
db/OLFDODSJFsetupProxy.js
Normal file
@ -0,0 +1,5 @@
|
||||
const proxy = require('http-proxy-middleware')
|
||||
|
||||
module.exports = app => {
|
||||
app.use(proxy('/api/*', { target: 'http://localhost:1337/' }))
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
const Item = require('./item')
|
||||
const Article = require('./article')
|
||||
|
||||
module.exports = { Item, Article }
|
||||
module.exports = { Item }
|
||||
|
44
db/seed.js
44
db/seed.js
@ -1,37 +1,25 @@
|
||||
const db = require('../db')
|
||||
const fs = require("fs")
|
||||
const { Item, Article } = require('./models')
|
||||
|
||||
const desert = fs.readFileSync("/home/notnull/projex/bootstrap/server/db/desert.txt", "utf8")
|
||||
|
||||
const { Item } = require('./models')
|
||||
|
||||
const testItem = {
|
||||
name: 'item'
|
||||
name: 'item'
|
||||
}
|
||||
|
||||
const testArticle = {
|
||||
title: "Desert",
|
||||
text: desert
|
||||
|
||||
}
|
||||
|
||||
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 Item.create(testItem)
|
||||
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()
|
||||
|
27
index.js
27
index.js
@ -3,11 +3,11 @@ const path = require('path')
|
||||
const app = express()
|
||||
const morgan = require('morgan')
|
||||
const ascii = require('./ascii')
|
||||
//const proxy = require('http-proxy-middleware')
|
||||
const port = process.env.PORT || 1337
|
||||
ALL YOUR BASE ARE BELONG TO US
|
||||
|
||||
app.use(morgan('tiny'))
|
||||
YOU HAVE NO CHANCE TO SURVIVE MAKE YOUR TIME
|
||||
HA HA HA
|
||||
|
||||
// body parsing middleware
|
||||
app.use(express.json())
|
||||
app.use(express.urlencoded({ extended: true }))
|
||||
@ -16,24 +16,11 @@ 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.use(express.static(path.join(__dirname, 'dist')))
|
||||
}
|
||||
|
||||
|
||||
// app.get('/articles', async (req, res, next) => {
|
||||
// try {
|
||||
// const articles = await Article.findAll()
|
||||
// console.log(articles)
|
||||
|
||||
// res.status(201).send(articles)
|
||||
// } catch (err) {
|
||||
// next(err)
|
||||
// }
|
||||
// })
|
||||
|
||||
app.get('*', (req, res) =>
|
||||
res.sendFile(path.resolve(__dirname, '..', 'client', 'public', 'index.html'))
|
||||
)
|
||||
app.get('*', (req, res) => {
|
||||
res.sendFile(path.resolve(__dirname, '..', 'public', 'index.html'))
|
||||
})
|
||||
|
||||
// error handling endware
|
||||
app.use((err, req, res, next) => {
|
||||
|
28
package-lock.json
generated
28
package-lock.json
generated
@ -993,11 +993,13 @@
|
||||
},
|
||||
"balanced-match": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true
|
||||
"bundled": true,
|
||||
"optional": true
|
||||
},
|
||||
"brace-expansion": {
|
||||
"version": "1.1.11",
|
||||
"bundled": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"balanced-match": "^1.0.0",
|
||||
"concat-map": "0.0.1"
|
||||
@ -1010,15 +1012,18 @@
|
||||
},
|
||||
"code-point-at": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true
|
||||
"bundled": true,
|
||||
"optional": true
|
||||
},
|
||||
"concat-map": {
|
||||
"version": "0.0.1",
|
||||
"bundled": true
|
||||
"bundled": true,
|
||||
"optional": true
|
||||
},
|
||||
"console-control-strings": {
|
||||
"version": "1.1.0",
|
||||
"bundled": true
|
||||
"bundled": true,
|
||||
"optional": true
|
||||
},
|
||||
"core-util-is": {
|
||||
"version": "1.0.2",
|
||||
@ -1121,7 +1126,8 @@
|
||||
},
|
||||
"inherits": {
|
||||
"version": "2.0.3",
|
||||
"bundled": true
|
||||
"bundled": true,
|
||||
"optional": true
|
||||
},
|
||||
"ini": {
|
||||
"version": "1.3.5",
|
||||
@ -1131,6 +1137,7 @@
|
||||
"is-fullwidth-code-point": {
|
||||
"version": "1.0.0",
|
||||
"bundled": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"number-is-nan": "^1.0.0"
|
||||
}
|
||||
@ -1143,17 +1150,20 @@
|
||||
"minimatch": {
|
||||
"version": "3.0.4",
|
||||
"bundled": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"brace-expansion": "^1.1.7"
|
||||
}
|
||||
},
|
||||
"minimist": {
|
||||
"version": "0.0.8",
|
||||
"bundled": true
|
||||
"bundled": true,
|
||||
"optional": true
|
||||
},
|
||||
"minipass": {
|
||||
"version": "2.3.5",
|
||||
"bundled": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"safe-buffer": "^5.1.2",
|
||||
"yallist": "^3.0.0"
|
||||
@ -1170,6 +1180,7 @@
|
||||
"mkdirp": {
|
||||
"version": "0.5.1",
|
||||
"bundled": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"minimist": "0.0.8"
|
||||
}
|
||||
@ -1242,7 +1253,8 @@
|
||||
},
|
||||
"number-is-nan": {
|
||||
"version": "1.0.1",
|
||||
"bundled": true
|
||||
"bundled": true,
|
||||
"optional": true
|
||||
},
|
||||
"object-assign": {
|
||||
"version": "4.1.1",
|
||||
@ -1252,6 +1264,7 @@
|
||||
"once": {
|
||||
"version": "1.4.0",
|
||||
"bundled": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"wrappy": "1"
|
||||
}
|
||||
@ -1357,6 +1370,7 @@
|
||||
"string-width": {
|
||||
"version": "1.0.2",
|
||||
"bundled": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"code-point-at": "^1.0.0",
|
||||
"is-fullwidth-code-point": "^1.0.0",
|
||||
|
@ -15,7 +15,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"seed": "node db/seed.js",
|
||||
"start": "nodemon server"
|
||||
"start": "nodemon index.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
Loading…
Reference in New Issue
Block a user