Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-Aftab committed Feb 15, 2021
0 parents commit 5605f0b
Show file tree
Hide file tree
Showing 21 changed files with 6,660 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
bundle.js
bundle.js.map
secrets.js
**/resources/static/assets/tmp
**/resources/static/assets/uploads
.env
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# myDiary

Diary based website that utilizes Artificial Intelligence to detect the sentiment analysis of the user’s diary entry. This project used Node.js, Express, PostgreSQL, and Sequelize.

## Get Started

To run this application:

1. In your terminal type `git clone https://github.com/Ali-Aftab/myDiary.git` to clone it to your computer.
2. Then type `cd myDiary` to access the folder
3. To install the required modules type `npm i`
4. Make a new PostgreSQL database by writing `createdb myDiary`
5. Create a .env file by typing `touch .env` to store your secret keys
6. In the .env file type `SECRET_JWT_KEY=ENTERYOURKEYHERE`
7. Type `npm run start-dev` in your terminal and you can use the API!

## API

First, we recommend installing [Postman](https://www.postman.com/) to easily test out the API. Remember to add `localhost:8000` to the URL before typing in the API path. (`/api/auth/signup`=>`localhost:8000/api/signup`)

### Sign Up/ Login Routes

How to signup and login.

- POST `/api/auth/signup` allows anyone to make an account <br/>
&nbsp;&nbsp;-Requires an email and password key inside the body <br/>
&nbsp;&nbsp;-Example {email: [email protected], password: password1} <br/>
- POST `/api/auth/signin` when logged in, the response will give the user an access token. The access token must be placed in the header (with "x-access-token" as the key and the given accessToken as the value)
&nbsp;&nbsp;-Requires an email and password key inside the body. Also the x-access-token inside the header.<br/>
&nbsp;&nbsp;-The x-access-token lasts for 24 hours. <br/>
Empty file added client/components/Login.js
Empty file.
10 changes: 10 additions & 0 deletions client/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from "react";
import ReactDOM from "react-dom";
import Main from "./main";

ReactDOM.render(
<div>
<Main />
</div>,
document.getElementById("app")
);
10 changes: 10 additions & 0 deletions client/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from "react";

export default function main() {
const [isLoggedIn, setIsLoggedIn] = useState(false);
return (
<div>
<h1>Hi</h1>
</div>
);
}
54 changes: 54 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const path = require("path");
const express = require("express");
const app = express();
const { db, User } = require("./server/db");
const PORT = process.env.PORT || 8000;
// const seed = require('./seed.js');
global.__basedir = __dirname;
require("dotenv").config();

//--------------------->Body parser <---------------------//
const bodyParser = require("body-parser");
app.use(bodyParser.json());
app.use(
bodyParser.urlencoded({
extended: true,
})
);

//--------------------->Loggin middleware morgan https://github.com/expressjs/morgan <---------------------//
const morgan = require("morgan");
app.use(morgan("dev"));

//--------------------->Serving javascript files, css files, and images from public folder<---------------------//
//https://expressjs.com/en/starter/static-files.html

// static file-serving middleware
app.use(express.static(path.join(__dirname, ".", "public")));

// API routes are prefixed with /api/ -
// this is purely done to namespace them away from your "front-end routes" (such as those created by react-router).
// app.use("/api", require("./server/apiRoutes")); // matches all requests to /api
require("./server/routes/auth.route")(app);
require("./server/routes/user.route")(app);

app.get("*", function (req, res, next) {
res.sendFile(path.join(__dirname, "./public/index.html"));
});
app.use(function (err, req, res, next) {
console.error(err);
console.error(err.stack);
res.status(err.status || 500).send(err.message || "Internal server error.");
});

//--------------------->Starting server<--------------------- //

const startServer = () => {
const server = app.listen(process.env.PORT || PORT, () =>
console.log(`Listening on ${PORT}`)
);
};
(async () => {
await db.sync({});
console.log("db sync");
})(startServer());
Loading

0 comments on commit 5605f0b

Please sign in to comment.