Skip to content

Commit c5a3d8b

Browse files
committed
final touches
1 parent 20da914 commit c5a3d8b

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

db.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
const Sequelize = require('sequelize')
22
const NoteModel = require('./models/Note')
3-
const sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASSWORD, {
4-
dialect: 'mysql',
5-
host: process.env.DB_HOST,
6-
port: process.env.DB_PORT
7-
})
3+
const sequelize = new Sequelize(
4+
process.env.DB_NAME,
5+
process.env.DB_USER,
6+
process.env.DB_PASSWORD,
7+
{
8+
dialect: 'mysql',
9+
host: process.env.DB_HOST,
10+
port: process.env.DB_PORT
11+
}
12+
)
813
const Note = NoteModel(sequelize, Sequelize)
914
const Models = { Note }
1015
const connection = {}
16+
1117
module.exports = async () => {
1218
if (connection.isConnected) {
1319
console.log('=> Using existing connection.')

handler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ module.exports.getAll = async () => {
6969
}
7070

7171
module.exports.update = async (event) => {
72-
const input = JSON.parse(event.body)
7372
try {
73+
const input = JSON.parse(event.body)
7474
const { Note } = await connectToDatabase()
7575
const note = await Note.findById(event.pathParameters.id)
7676
if (!note) throw new HTTPError(404, `Note with id: ${event.pathParameters.id} was not found`)

sample.secrets.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"DB_NAME": "test",
3-
"DB_USER": "admin",
4-
"DB_PASSWORD": "admin",
5-
"DB_HOST": "localhost",
3+
"DB_USER": "root",
4+
"DB_PASSWORD": "root",
5+
"DB_HOST": "127.0.0.1",
66
"DB_PORT": 3306,
77
"NODE_ENV": "dev",
88
"SECURITY_GROUP_ID": "sg-xx",

serverless.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
service: rest-api
1+
service: web-api
22

33
custom:
44
secrets: ${file(secrets.json)}

0 commit comments

Comments
 (0)