Browse Source

first

master
void 4 months ago
parent
commit
7f18194cbf
6 changed files with 2192 additions and 0 deletions
  1. 2
    0
      .gitignore
  2. 30
    0
      index.js
  3. 7
    0
      knexfile.js
  4. 15
    0
      migrations/20190430212923_create_logs_table.js
  5. 18
    0
      package.json
  6. 2120
    0
      pnpm-lock.yaml

+ 2
- 0
.gitignore View File

@@ -76,3 +76,5 @@ typings/
76 76
 # FuseBox cache
77 77
 .fusebox/
78 78
 
79
+# databases
80
+*.sqlite3

+ 30
- 0
index.js View File

@@ -0,0 +1,30 @@
1
+const PORT = process.env.PORT || 1984
2
+
3
+const express = require('express')
4
+const app = express()
5
+const knex = require('knex')(require('./knexfile'))
6
+
7
+app.use((req, res, next) => {
8
+  res.header("Access-Control-Allow-Origin", "*")
9
+  res.header("Access-Control-Max-Age", "360000") // prevent making another OPTIONS request in 3600 seconds
10
+  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
11
+  next()
12
+})
13
+
14
+app.post('/', async (req, res) => {
15
+  const log = {
16
+    app_name: req.query.appName,
17
+    client_id: req.query.id,
18
+    data: req.query.data,
19
+    headers: JSON.stringify(req.headers),
20
+  }
21
+
22
+  console.log(log)
23
+  await knex('logs').insert(log)
24
+
25
+  res.status(200).json({ success: true })
26
+})
27
+
28
+app.listen(PORT, () => {
29
+  console.log(`listening @ ${PORT}`)
30
+})

+ 7
- 0
knexfile.js View File

@@ -0,0 +1,7 @@
1
+module.exports = {
2
+  client: 'sqlite3',
3
+  connection: {
4
+    filename: './db.sqlite3',
5
+  },
6
+  useNullAsDefault: true,
7
+}

+ 15
- 0
migrations/20190430212923_create_logs_table.js View File

@@ -0,0 +1,15 @@
1
+exports.up = function (knex, Promise) {
2
+  return knex.schema.createTable('logs', table => {
3
+    table.increments()
4
+    table.string('data').notNullable()
5
+    table.string('client_id').notNullable()
6
+    table.string('app_name').notNullable()
7
+    table.string('headers').notNullable()
8
+    table.timestamp('created_at').defaultTo(knex.fn.now())
9
+    table.timestamp('updated_at').defaultTo(knex.fn.now())
10
+  })
11
+}
12
+
13
+exports.down = function (knex, Promise) {
14
+  return knex.schema.dropTable('logs')
15
+}

+ 18
- 0
package.json View File

@@ -0,0 +1,18 @@
1
+{
2
+  "name": "papas-dia-backend",
3
+  "version": "0.1.0",
4
+  "description": "el backend para capturar logs como unx campeón",
5
+  "main": "index.js",
6
+  "scripts": {
7
+    "test": "echo \"Error: no test specified\" && exit 1",
8
+    "migrate": "knex migrate:latest"
9
+  },
10
+  "keywords": [],
11
+  "author": "void <v0id@riseup.net>",
12
+  "license": "AGPL-3.0-only",
13
+  "dependencies": {
14
+    "express": "^4.16.4",
15
+    "knex": "^0.16.5",
16
+    "sqlite3": "^4.0.6"
17
+  }
18
+}

+ 2120
- 0
pnpm-lock.yaml
File diff suppressed because it is too large
View File


Loading…
Cancel
Save