Skip to content

Commit

Permalink
Merge pull request #34 from ChicoState/chico_arrest
Browse files Browse the repository at this point in the history
Chico arrests
  • Loading branch information
evanalba authored Dec 9, 2024
2 parents 1a84e68 + 0d003d5 commit bcf9829
Show file tree
Hide file tree
Showing 9 changed files with 1,518 additions and 20 deletions.
1 change: 1 addition & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodes_modules
42 changes: 39 additions & 3 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,48 @@
#added more dependency here to work with the web scraper

# Node backend setup
FROM node:22
FROM node:22

# We do not need the standalone Chromium
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true

# Install Google Chrome Stable and fonts
# Note: this installs the necessary libs to make the browser work with Puppeteer.
RUN apt-get update && apt-get install curl gnupg -y \
&& curl --location --silent https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install google-chrome-stable -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src

# Copy package requirements and install
COPY package.json .
RUN npm install

# Additional dependencies for Puppeteer
RUN apt-get update && apt-get install -y \
libgtk-3-0 \
libnss3 \
libx11-xcb1 \
libxcomposite1 \
libxdamage1 \
libxrandr2 \
libgbm-dev \
libasound2 \
libpangocairo-1.0-0 \
libatk-bridge2.0-0 \
libatspi2.0-0 \
--no-install-recommends

# Copy current directory items over
COPY index.js .
COPY . .

RUN npm uninstall bcrypt
RUN npm install bcrypt

EXPOSE 8080

# Run index.js
CMD ["node", "index.js"]
CMD ["node", "index.js"]
24 changes: 23 additions & 1 deletion backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import mongoose from "mongoose";
import dotenv from "dotenv"
import bodyParser from "body-parser";
import bcrypt from "bcrypt";
import * as scraper from "./scraper.js"

dotenv.config();

Expand All @@ -28,7 +29,28 @@ app.listen(port, () => {
console.log(`Running at http://${hostname}:${port}/`);
});

/* FBI API Functionality */
app.get("/", (req, res) => {
res.send("Hello, StaySafe backend!")
});

app.get("/scrape-chico", async (req, res) => {
try {
const data = await scraper.getData();
res.json(data);
} catch (error) {
console.error('Error scraping Chico data:', error);
}
});

app.post('/api/search', (req, res) => {
let { county, location, state } = req.body;
county = county.replace(/\s[Cc]ounty$/, '');
lastSearch = { county, location, state };

console.log('Received data:', lastSearch);
res.status(200).json({ message: 'Data stored successfully', data: lastSearch });
});

app.get('/api/fbi/crime-stats', async (req, res) => {
const crime_types = [
"aggravated-assault",
Expand Down
Loading

0 comments on commit bcf9829

Please sign in to comment.