Skip to content

Commit

Permalink
Reorganiza estrutura de arquivos
Browse files Browse the repository at this point in the history
  • Loading branch information
guipratiko committed Feb 3, 2025
1 parent c6e5c4b commit 5567be8
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MONGODB_URI=mongodb+srv://autostore_admin:<db_password>@cluster0.rs3sm.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0
PORT=3000
15 changes: 10 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- name: Deploy to Digital Ocean
uses: appleboy/ssh-action@master
with:
node-version: '16'
- run: npm install
- run: npm run build
host: ${{ secrets.DROPLET_IP }}
username: root
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /var/www/luizautomoveis
git pull
npm install
pm2 restart luizautomoveis
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
# Dependências
node_modules/
npm-debug.log
yarn-debug.log
yarn-error.log

# Ambiente
.env
.env.local
.env.*.local

# Sistema
.DS_Store
Thumbs.db

# IDE/Editor
.idea/
.vscode/
*.swp
*.swo

# Logs
logs
*.log

# Build
dist/
build/
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "luiz-automoveis",
"version": "1.0.0",
"description": "Site de venda de veículos",
"main": "server.js",
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js"
},
"dependencies": {
"express": "^4.18.2",
"mongoose": "^7.0.0",
"cors": "^2.8.5",
"dotenv": "^16.0.3"
},
"devDependencies": {
"nodemon": "^2.0.22"
}
}
File renamed without changes.
4 changes: 4 additions & 0 deletions index.html → public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ <h3>Luiz Automóveis</h3>
</div>
</footer>

<div class="test-deploy">
<h3>Teste de Deploy Automático</h3>
</div>

<script src="/js/main.js"></script>
</body>
</html>
5 changes: 5 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
cd /var/www/luizautomoveis
git pull
npm install
pm2 restart luizautomoveis
30 changes: 20 additions & 10 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
const path = require('path');
require('dotenv').config();

const app = express();

// Configuração do middleware
// Middleware
app.use(cors());
app.use(express.json());
app.use(express.static('public'));

// Conexão com MongoDB
mongoose.connect(process.env.MONGODB_URI, {
// Mover arquivos estáticos para pasta public
app.use(express.static(path.join(__dirname, 'public')));

// Configurar diretório de views
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});

// Conexão MongoDB
const mongoURI = process.env.MONGODB_URI || 'mongodb://localhost:27017/luizautomoveis';
mongoose.connect(mongoURI, {
useNewUrlParser: true,
useUnifiedTopology: true
});
})
.then(() => console.log('MongoDB Conectado'))
.catch(err => console.log('Erro na conexão MongoDB:', err));

const db = mongoose.connection;
db.on('error', console.error.bind(console, 'Erro de conexão:'));
db.once('open', () => {
console.log('Conectado ao MongoDB!');
// Rotas básicas
app.get('/api/health', (req, res) => {
res.json({ status: 'OK' });
});

// Rotas serão adicionadas aqui

// Iniciar servidor
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Servidor rodando na porta ${PORT}`);
Expand Down
64 changes: 64 additions & 0 deletions src/models/Vehicle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const mongoose = require('mongoose');

const vehicleSchema = new mongoose.Schema({
marca: {
type: String,
required: true,
enum: ['Fiat', 'Chevrolet', 'Volkswagen', 'Ford', 'Toyota', 'Honda', 'Hyundai', 'Renault', 'Nissan', 'Jeep']
},
modelo: {
type: String,
required: true
},
cor: {
type: String,
required: true,
enum: ['Branco', 'Preto', 'Prata', 'Cinza', 'Azul metálico', 'Verde metálico', 'Vermelho metálico']
},
anoFabricacao: {
type: Number,
required: true,
min: 1960,
max: new Date().getFullYear() + 1
},
finalPlaca: {
type: Number,
required: true,
min: 0,
max: 9
},
quilometragem: {
type: Number,
required: true,
min: 0
},
combustivel: {
type: String,
required: true,
enum: ['Elétrico', 'Híbrido', 'Flex', 'Álcool', 'Gasolina', 'Diesel']
},
transmissao: {
type: String,
required: true,
enum: ['Manual', 'Automático', 'CVT', 'Semi-automático']
},
fotos: [{
type: String,
required: true
}],
preco: {
type: Number,
required: true
},
descricao: String,
destaque: {
type: Boolean,
default: false
},
dataCadastro: {
type: Date,
default: Date.now
}
});

module.exports = mongoose.model('Vehicle', vehicleSchema);

0 comments on commit 5567be8

Please sign in to comment.