mirror of
https://github.com/UniversityOfHelsinkiCS/ohtuilmo.git
synced 2026-10-12 19:03:41 +03:00
Initial commit with project structure
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
.env
|
||||
@@ -0,0 +1,16 @@
|
||||
## Installation
|
||||
Clone and run:
|
||||
npm install
|
||||
|
||||
## Instructions
|
||||
Create .env files and add following lines:
|
||||
|
||||
"
|
||||
DATABASE_URI=TODO
|
||||
PORT=3001
|
||||
|
||||
TEST_PORT=3002
|
||||
TEST_DATABASE_URI=//
|
||||
"
|
||||
|
||||
Run "npm run watch" to run the project in watch mode
|
||||
@@ -0,0 +1,22 @@
|
||||
const examplesRouter = require('express').Router()
|
||||
const Example = require('../models/example')
|
||||
|
||||
|
||||
// examplesRouter.get('/', async (request, response) => {
|
||||
// const examples = await Example
|
||||
// .find({})
|
||||
// response.json(examples)
|
||||
// })
|
||||
|
||||
// examplesRouter.post('/', async (request, response) => {
|
||||
// try {
|
||||
// const example = new Example(request.body.content)
|
||||
// const result = await example.save();
|
||||
// return response.status(201).json(result);
|
||||
// } catch (exception) {
|
||||
// console.log(exception)
|
||||
// }
|
||||
// })
|
||||
|
||||
|
||||
module.exports = examplesRouter
|
||||
@@ -0,0 +1,41 @@
|
||||
const http = require('http')
|
||||
const express = require('express')
|
||||
const app = express()
|
||||
const bodyParser = require('body-parser')
|
||||
const cors = require('cors')
|
||||
const pg = require('pg');
|
||||
const config = require('./utils/config')
|
||||
|
||||
|
||||
// Middleware
|
||||
app.use(cors())
|
||||
app.use(bodyParser.json())
|
||||
|
||||
|
||||
// Routers
|
||||
const examplesRouter = require('./controllers/examples')
|
||||
app.use('/api/examples', examplesRouter)
|
||||
|
||||
|
||||
// Database connection
|
||||
// const connectionString = process.env.DATABASE_URI || 'postgres://localhost:5432/todo';
|
||||
// const client = new pg.Client(connectionString)
|
||||
// client.connect();
|
||||
|
||||
// Initialize server
|
||||
const PORT = config.port
|
||||
const server = http.createServer(app)
|
||||
server.listen(PORT, () => {
|
||||
console.log(`Server running on port ${config.port}`)
|
||||
})
|
||||
|
||||
server.on('close', () => {
|
||||
// Close database connection
|
||||
client.end()
|
||||
.then(() => console.log('client has disconnected'))
|
||||
.catch(() => console.error('error during disconnection', err.stack))
|
||||
})
|
||||
|
||||
module.exports = {
|
||||
app, server
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
// Sequelize models here!!!!!
|
||||
Generated
+3700
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "retrospective-tool-backend",
|
||||
"version": "1.0.0",
|
||||
"description": "Node.js backend for retrospective tool",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"watch": "cross-env NODE_ENV=development nodemon index.js",
|
||||
"start": "cross-env NODE_ENV=production node index.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/ohtuprojekti-ilmo/ohtuilmo-backend.git"
|
||||
},
|
||||
"keywords": [
|
||||
"node"
|
||||
],
|
||||
"author": "jexniemi",
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/ohtuprojekti-ilmo/ohtuilmo-backend/issues"
|
||||
},
|
||||
"homepage": "https://github.com/ohtuprojekti-ilmo/ohtuilmo-backend#readme",
|
||||
"dependencies": {
|
||||
"body-parser": "^1.18.2",
|
||||
"cors": "^2.8.4",
|
||||
"dotenv": "^5.0.1",
|
||||
"express": "^4.16.3",
|
||||
"pg": "^7.4.3",
|
||||
"sequelize": "^4.38.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"cross-env": "^5.1.4",
|
||||
"nodemon": "^1.17.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
require('dotenv').config()
|
||||
}
|
||||
|
||||
let port = process.env.PORT
|
||||
let dbUrl = process.env.DATABASE_URI
|
||||
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
port = process.env.TEST_PORT
|
||||
dbUrl = process.env.TEST_DATABASE_URI
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
dbUrl,
|
||||
port
|
||||
}
|
||||
Reference in New Issue
Block a user